update debug
This commit is contained in:
parent
829735eb8c
commit
b87ebbe841
14
njvm.c
14
njvm.c
@ -35,6 +35,10 @@ void execute(struct program program) {
|
||||
unsigned int temp;
|
||||
char charInput;
|
||||
for (i = 0; i < *program.size; ++i) {
|
||||
if (debug == 1) printf("=== DEBUG: Stack before instruction %i ===\n", i);
|
||||
if (debug == 1) printStack(stack, fp);
|
||||
if (debug == 1) printf("=== DEBUG: Instruction %i ===\n", i);
|
||||
|
||||
switch (program.program[i] >> 24) {
|
||||
case HALT:
|
||||
if (debug == 1) printf("halt\n");
|
||||
@ -101,11 +105,9 @@ void execute(struct program program) {
|
||||
*stack.current = *stack.current + SIGN_EXTEND(IMMEDIATE(program.program[i]));
|
||||
break;
|
||||
case RSF:
|
||||
if (debug == 1) printStack(stack, fp);
|
||||
if (debug == 1) printf("rsf\n");
|
||||
*stack.current = fp + 2;
|
||||
fp = pop(stack);
|
||||
if (debug == 1) printStack(stack, fp);
|
||||
break;
|
||||
case POPL:
|
||||
if (debug == 1) printf("popl: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
|
||||
@ -164,29 +166,29 @@ void execute(struct program program) {
|
||||
i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1;
|
||||
if (debug == 1) printf("new i: %i\n", i);
|
||||
}
|
||||
break;
|
||||
case JMP:
|
||||
if (debug == 1) printf("jmp: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
|
||||
i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1;
|
||||
if (debug == 1) printf("new i: %i\n", i);
|
||||
break;
|
||||
case CALL:
|
||||
if (debug == 1) printStack(stack, fp);
|
||||
if (debug == 1) printf("call: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
|
||||
push(stack, i + 1);
|
||||
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);
|
||||
if (debug == 1) printStack(stack, fp);
|
||||
break;
|
||||
case RET:
|
||||
if (debug == 1) printStack(stack, fp);
|
||||
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);
|
||||
if (debug == 1) printStack(stack, fp);
|
||||
break;
|
||||
}
|
||||
if (debug == 1) printf("=== DEBUG: Stack after instruction %i ===\n", i);
|
||||
if (debug == 1) printStack(stack, fp);
|
||||
if (debug == 1) printf("=== DEBUG: Instruction %i ===\n", i);
|
||||
}
|
||||
end:
|
||||
return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user