Aufgabe 2 Fertig
This commit is contained in:
parent
83dae77e31
commit
7390df9ee0
2
consts.c
2
consts.c
@ -1,6 +1,6 @@
|
||||
#ifndef CONSTS
|
||||
#define CONSTS
|
||||
#define VERSION 4
|
||||
#define VERSION 2
|
||||
|
||||
#endif /* ifndef CONSTS
|
||||
#define CONSTS
|
||||
|
||||
5
njvm.c
5
njvm.c
@ -82,11 +82,11 @@ void execute(struct program program) {
|
||||
break;
|
||||
case ASF:
|
||||
push(stack, *stack.current);
|
||||
fp = *stack.current;
|
||||
fp = *stack.current - 1;
|
||||
*stack.current = *stack.current + SIGN_EXTEND(IMMEDIATE(program.program[i]));
|
||||
break;
|
||||
case RSF:
|
||||
*stack.current = fp;
|
||||
*stack.current = fp + 2;
|
||||
fp = pop(stack);
|
||||
case POPL:
|
||||
stack.stack[fp + SIGN_EXTEND(IMMEDIATE(program.program[i]))] = pop(stack);
|
||||
@ -99,7 +99,6 @@ void execute(struct program program) {
|
||||
end:
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
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);
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user