update debug

fix call not jumping
This commit is contained in:
Elias Bennour 2023-12-09 22:42:46 +01:00
parent 61a138fdee
commit c0a5e694c0
2 changed files with 29 additions and 5 deletions

8
njvm.c
View File

@ -167,10 +167,16 @@ void execute(struct program program) {
if (debug == 1) printf("new i: %i\n", i);
break;
case CALL:
push(stack, i+1);
if (debug == 1) printf("call: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
push(stack, i + 1);
i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1;
if (debug == 1) printf("new i: %i\n", i);
break;
case RET:
if (debug == 1) printf("ret\n");
if (debug == 1) printf("pop: %i\n", peek(stack, 1));
i = pop(stack);
if (debug == 1) printf("new i: %i\n", i);
break;
}
}

View File

@ -104,6 +104,24 @@ void printProgram(struct program program) {
case BRT:
strcpy(c, "brt");
break;
case CALL:
strcpy(c, "call");
break;
case RET:
strcpy(c, "ret");
break;
case DROP:
strcpy(c, "drop");
break;
case PUSHR:
strcpy(c, "pushr");
break;
case POPR:
strcpy(c, "popr");
break;
case DUP:
strcpy(c, "dup");
break;
default:
strcpy(c, "ERROR");
break;