diff --git a/src/emulate.c b/src/emulate.c index 54b0d68..dc61a34 100755 --- a/src/emulate.c +++ b/src/emulate.c @@ -31,21 +31,23 @@ int main(int argc, char **argv) { state->conditionCodes = (PState){0, 1, 0, 0}; state->pc = 0x0; - // get + // Fetch-decode-execute cycle + word wrd; a64inst_instruction *inst; - do { - word instruction = readWord(state, state->pc); - inst = decode(instruction); - execute(state, inst); + // Step 1: Fetch instruction at PC's address + wrd = readWord(state, 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; - } while (inst->type != a64inst_HALT); printState(state, out); - free(state->memory); return EXIT_SUCCESS;