From 82dc5f28cc8f0b8c7cca5f6cb623d48779ab073b Mon Sep 17 00:00:00 2001 From: Nils Polek Date: Sat, 9 Dec 2023 23:43:33 +0100 Subject: [PATCH] abc --- njvm.c | 7 +++++-- programs/prog02.asm | 28 ++++++++++++++++++++++++++++ programs/prog02.bin | Bin 0 -> 104 bytes programs/prog3.bin | Bin 52 -> 52 bytes programs/prog7.asm | 2 +- programs/prog7.bin | Bin 60 -> 60 bytes 6 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 programs/prog02.asm create mode 100644 programs/prog02.bin 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 0000000000000000000000000000000000000000..fe3f26814261bd019cbd36961ff90d732cb6868c GIT binary patch literal 104 zcmebCa&lu~U|`PVs-`wDJBL68K5v9NDj#6{qz4nKak161(XNU TTtIyw8qWWVCJ&SY>6Hcmq_zlu literal 0 HcmV?d00001 diff --git a/programs/prog3.bin b/programs/prog3.bin index f4885ea710cfd193f55e21ff718accbeff38654b..04a0f3cca1396768f6173fa566fc373f78d63473 100644 GIT binary patch delta 11 ScmXppVfFKJa$}just*7S*aBAo delta 11 ScmXppVfFKJa$}mvst*7S&;nHe 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 d7f48a5e6ef9934b5e5b73da5d4e867df7b18112..6d474adaf7811dfa9d41c974bdd98f0b45d2444f 100644 GIT binary patch delta 25 ccmcDqnV=!U$iTqM#lQfh7=RQ59}r6e03Y%JkpKVy delta 25 ccmcDqnV=!Uz`(%E#lXM_q=6Iz9}r6e03Y4~kN^Mx