Aufgabe 2 Fertig
This commit is contained in:
parent
83dae77e31
commit
7390df9ee0
2
consts.c
2
consts.c
@ -1,6 +1,6 @@
|
|||||||
#ifndef CONSTS
|
#ifndef CONSTS
|
||||||
#define CONSTS
|
#define CONSTS
|
||||||
#define VERSION 4
|
#define VERSION 2
|
||||||
|
|
||||||
#endif /* ifndef CONSTS
|
#endif /* ifndef CONSTS
|
||||||
#define CONSTS
|
#define CONSTS
|
||||||
|
|||||||
5
njvm.c
5
njvm.c
@ -82,11 +82,11 @@ void execute(struct program program) {
|
|||||||
break;
|
break;
|
||||||
case ASF:
|
case ASF:
|
||||||
push(stack, *stack.current);
|
push(stack, *stack.current);
|
||||||
fp = *stack.current;
|
fp = *stack.current - 1;
|
||||||
*stack.current = *stack.current + SIGN_EXTEND(IMMEDIATE(program.program[i]));
|
*stack.current = *stack.current + SIGN_EXTEND(IMMEDIATE(program.program[i]));
|
||||||
break;
|
break;
|
||||||
case RSF:
|
case RSF:
|
||||||
*stack.current = fp;
|
*stack.current = fp + 2;
|
||||||
fp = pop(stack);
|
fp = pop(stack);
|
||||||
case POPL:
|
case POPL:
|
||||||
stack.stack[fp + SIGN_EXTEND(IMMEDIATE(program.program[i]))] = pop(stack);
|
stack.stack[fp + SIGN_EXTEND(IMMEDIATE(program.program[i]))] = pop(stack);
|
||||||
@ -99,7 +99,6 @@ void execute(struct program program) {
|
|||||||
end:
|
end:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
void tests(void) {
|
void tests(void) {
|
||||||
|
|||||||
9
programs/prog3.asm
Normal file
9
programs/prog3.asm
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
pushc 1
|
||||||
|
asf 2
|
||||||
|
asf 4
|
||||||
|
pushc 23
|
||||||
|
asf 3
|
||||||
|
rsf
|
||||||
|
rsf
|
||||||
|
rsf
|
||||||
|
halt
|
||||||
BIN
programs/prog3.bin
Normal file
BIN
programs/prog3.bin
Normal file
Binary file not shown.
5
stack.c
5
stack.c
@ -13,9 +13,10 @@ struct stack {
|
|||||||
unsigned int *stack;
|
unsigned int *stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
void printStack(struct stack stack) {
|
void printStack(struct stack stack, int fp) {
|
||||||
printf("Stack\nSize:\t\t%i\nCurrent:\t%i\n", *stack.size, *stack.current);
|
printf("Stack\nSize:\t\t%i\nCurrent:\t%i\n", *stack.size, *stack.current);
|
||||||
for (int i = 0; i < *stack.size; ++i) {
|
for (int i = 0; i < *stack.current; ++i) {
|
||||||
|
if(fp == i) printf("|FP|\n");
|
||||||
printf("|%i|\n", stack.stack[i]);
|
printf("|%i|\n", stack.stack[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user