fix jump not working right

This commit is contained in:
Elias Bennour 2023-12-09 22:10:02 +01:00
parent 27400289f5
commit 55af679c39

6
njvm.c
View File

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