abc
This commit is contained in:
parent
8be99c5244
commit
82dc5f28cc
7
njvm.c
7
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);
|
||||
|
||||
28
programs/prog02.asm
Normal file
28
programs/prog02.asm
Normal 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
BIN
programs/prog02.bin
Normal file
Binary file not shown.
Binary file not shown.
@ -10,7 +10,7 @@
|
||||
halt
|
||||
|
||||
proc:
|
||||
asf 0
|
||||
asf 1
|
||||
pushc '\n'
|
||||
wrchr
|
||||
rsf
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user