update debug

This commit is contained in:
Elias Bennour 2023-12-09 22:51:27 +01:00
parent 5a7338f91c
commit 44f70a1777

4
njvm.c
View File

@ -101,9 +101,11 @@ void execute(struct program program) {
*stack.current = *stack.current + SIGN_EXTEND(IMMEDIATE(program.program[i])); *stack.current = *stack.current + SIGN_EXTEND(IMMEDIATE(program.program[i]));
break; break;
case RSF: case RSF:
if (debug == 1) printStack(stack, fp);
if (debug == 1) printf("rsf\n"); if (debug == 1) printf("rsf\n");
*stack.current = fp + 2; *stack.current = fp + 2;
fp = pop(stack); fp = pop(stack);
if (debug == 1) printStack(stack, fp);
case POPL: case POPL:
if (debug == 1) printf("popl: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); if (debug == 1) printf("popl: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
stack.stack[fp + SIGN_EXTEND(IMMEDIATE(program.program[i]))] = pop(stack); stack.stack[fp + SIGN_EXTEND(IMMEDIATE(program.program[i]))] = pop(stack);
@ -167,11 +169,13 @@ void execute(struct program program) {
if (debug == 1) printf("new i: %i\n", i); if (debug == 1) printf("new i: %i\n", i);
break; break;
case CALL: case CALL:
if (debug == 1) printStack(stack, fp);
if (debug == 1) printf("call: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); if (debug == 1) printf("call: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
push(stack, i + 1); push(stack, i + 1);
if (debug == 1) printf("push: %i\n", i + 1); if (debug == 1) printf("push: %i\n", i + 1);
i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1; i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1;
if (debug == 1) printf("new i: %i\n", i); if (debug == 1) printf("new i: %i\n", i);
if (debug == 1) printStack(stack, fp);
break; break;
case RET: case RET:
if (debug == 1) printStack(stack, fp); if (debug == 1) printStack(stack, fp);