diff --git a/njvm.c b/njvm.c index f62342e..948f764 100644 --- a/njvm.c +++ b/njvm.c @@ -100,7 +100,7 @@ void execute(struct program program) { break; case ASF: if (debug == 1) printf("asf: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); - push(stack, *stack.current); + push(stack, fp); fp = *stack.current; *stack.current = *stack.current + SIGN_EXTEND(IMMEDIATE(program.program[i])); break; @@ -175,7 +175,7 @@ void execute(struct program program) { break; case CALL: if (debug == 1) printf("call: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); - push(stack, i + 1); + push(stack, i); if (debug == 1) printf("push: %i\n", i + 1); i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1; if (debug == 1) printf("new i: %i\n", i); @@ -186,6 +186,9 @@ void execute(struct program program) { i = pop(stack); if (debug == 1) printf("new i: %i\n", i); break; + case DROP: + *stack.current = *stack.current - SIGN_EXTEND(IMMEDIATE(program.program[i])); + break; } if (debug == 1) printf("=== DEBUG: Stack after instruction %i ===\n", i); if (debug == 1) printStack(stack, fp); diff --git a/programs/prog02.asm b/programs/prog02.asm new file mode 100644 index 0000000..eb3b037 --- /dev/null +++ b/programs/prog02.asm @@ -0,0 +1,28 @@ +// +// prog02.asm -- call/ret with args, but without ret value +// + + asf 3 + pushc 11 + pushc 33 + call proc + drop 2 + rsf + halt + +proc: + asf 2 + pushl -4 + wrint + pushc '\n' + wrchr + pushc 22 + wrint + pushc '\n' + wrchr + pushl -3 + wrint + pushc '\n' + wrchr + rsf + ret diff --git a/programs/prog02.bin b/programs/prog02.bin new file mode 100644 index 0000000..fe3f268 Binary files /dev/null and b/programs/prog02.bin differ diff --git a/programs/prog3.bin b/programs/prog3.bin index f4885ea..04a0f3c 100644 Binary files a/programs/prog3.bin and b/programs/prog3.bin differ diff --git a/programs/prog7.asm b/programs/prog7.asm index 554f3cc..e0a21fd 100644 --- a/programs/prog7.asm +++ b/programs/prog7.asm @@ -10,7 +10,7 @@ halt proc: - asf 0 + asf 1 pushc '\n' wrchr rsf diff --git a/programs/prog7.bin b/programs/prog7.bin index d7f48a5..6d474ad 100644 Binary files a/programs/prog7.bin and b/programs/prog7.bin differ