diff --git a/src/emulate.c b/src/emulate.c index 6720dd0..df2f471 100755 --- a/src/emulate.c +++ b/src/emulate.c @@ -2,6 +2,7 @@ #include #include "emulator.h" #include "fileio.h" +#include "global.h" #include "print.h" #include "decode.h" #include "execute.h" @@ -26,10 +27,11 @@ int main(int argc, char **argv) { } // Initialising the machine state - Machine *state = {0}; - state->memory = fileio_loadBin(argv[1], MEMORY_SIZE); - state->conditionCodes = (PState){0, 1, 0, 0}; - state->pc = 0x0; + Machine state = {0}; + state.memory = fileio_loadBin(argv[1], MEMORY_SIZE); + state.conditionCodes = (PState){0, 1, 0, 0}; + state.pc = 0x0; + // Fetch-decode-execute cycle word wrd; @@ -37,18 +39,21 @@ int main(int argc, char **argv) { do { // Step 1: Fetch instruction at PC's address - wrd = readWord(state->memory, state->pc); + wrd = readWord(state.memory, state.pc); // Step 2: Decode instruction to internal representation inst = decode(wrd); // Step 3: Update processor state to reflect executing the instruction, and increment PC - execute(state, inst); - state->pc += 1; + execute(&state, inst); + + state.pc += sizeof(word); } while (inst->type != a64inst_HALT); - printState(state, out); - free(state->memory); + state.pc -= sizeof(word); + + printState(&state, out); + free(state.memory); return EXIT_SUCCESS; }