Aufgabe 2 Fertig

This commit is contained in:
Nils Polek 2023-12-09 20:35:15 +01:00
parent 83dae77e31
commit 7390df9ee0
6 changed files with 15 additions and 6 deletions

View File

@ -1,6 +1,6 @@
#ifndef CONSTS
#define CONSTS
#define VERSION 4
#define VERSION 2
#endif /* ifndef CONSTS
#define CONSTS

5
njvm.c
View File

@ -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) {

View File

9
programs/prog3.asm Normal file
View 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

Binary file not shown.

View File

@ -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]);
}
}