From 55af679c39788523bdccb66ac27b3a6625831f52 Mon Sep 17 00:00:00 2001 From: Elias Bennour Date: Sat, 9 Dec 2023 22:10:02 +0100 Subject: [PATCH] fix jump not working right --- njvm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/njvm.c b/njvm.c index 07d50c8..9f6a71b 100644 --- a/njvm.c +++ b/njvm.c @@ -150,7 +150,7 @@ void execute(struct program program) { if (debug == 1) printf("brf: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); if (debug == 1) printf("pop: %i\n", peek(stack, 1)); if (pop(stack) == 0) { - i = SIGN_EXTEND(IMMEDIATE(program.program[i])); + i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1; if (debug == 1) printf("new i: %i\n", i); } break; @@ -158,12 +158,12 @@ void execute(struct program program) { if (debug == 1) printf("brt: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); if (debug == 1) printf("pop: %i\n", peek(stack, 1)); if (pop(stack) == 1) { - i = SIGN_EXTEND(IMMEDIATE(program.program[i])); + i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1; if (debug == 1) printf("new i: %i\n", i); } case JMP: if (debug == 1) printf("jmp: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); - i = SIGN_EXTEND(IMMEDIATE(program.program[i])); + i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1; if (debug == 1) printf("new i: %i\n", i); break; }