This commit is contained in:
Nils Polek 2023-12-09 23:43:33 +01:00
parent 8be99c5244
commit 82dc5f28cc
6 changed files with 34 additions and 3 deletions

7
njvm.c
View File

@ -100,7 +100,7 @@ void execute(struct program program) {
break; break;
case ASF: case ASF:
if (debug == 1) printf("asf: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); if (debug == 1) printf("asf: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
push(stack, *stack.current); push(stack, fp);
fp = *stack.current; fp = *stack.current;
*stack.current = *stack.current + SIGN_EXTEND(IMMEDIATE(program.program[i])); *stack.current = *stack.current + SIGN_EXTEND(IMMEDIATE(program.program[i]));
break; break;
@ -175,7 +175,7 @@ void execute(struct program program) {
break; break;
case CALL: case CALL:
if (debug == 1) printf("call: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); 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); if (debug == 1) printf("push: %i\n", i + 1);
i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1; i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1;
if (debug == 1) printf("new i: %i\n", i); if (debug == 1) printf("new i: %i\n", i);
@ -186,6 +186,9 @@ void execute(struct program program) {
i = pop(stack); i = pop(stack);
if (debug == 1) printf("new i: %i\n", i); if (debug == 1) printf("new i: %i\n", i);
break; 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) printf("=== DEBUG: Stack after instruction %i ===\n", i);
if (debug == 1) printStack(stack, fp); if (debug == 1) printStack(stack, fp);

28
programs/prog02.asm Normal file
View File

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

BIN
programs/prog02.bin Normal file

Binary file not shown.

Binary file not shown.

View File

@ -10,7 +10,7 @@
halt halt
proc: proc:
asf 0 asf 1
pushc '\n' pushc '\n'
wrchr wrchr
rsf rsf

Binary file not shown.