From 0e83e980b0dc355b642c069db82bb4aebfdf8228 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Thu, 8 Jul 2021 18:31:36 -0700 Subject: [PATCH] Addressed minor TODOs in simulator.c --- hacks/NEDsim/simulator.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/hacks/NEDsim/simulator.c b/hacks/NEDsim/simulator.c index 9c63b67..73623dc 100644 --- a/hacks/NEDsim/simulator.c +++ b/hacks/NEDsim/simulator.c @@ -172,9 +172,6 @@ ned_instruction_add(struct NEDstate * state) static void ned_instruction_shift(struct NEDstate * state) { - /* TODO: Bounds check: Either all inputs are valid OR shift_by < 32. */ - /* I guess this also depends if I'm shifting-and-dropping, or barrel-shifting. */ - /* How should I pad for a right shift if I shift-and-drop? Sign extend? */ uint32_t shift_by = stack_pop(state->active_thread); uint32_t word = stack_pop(state->active_thread); if (shift_by & 0x80000000) { @@ -431,19 +428,21 @@ run_simulator(struct NEDstate * state) stack_push(state->active_thread, (iw << 1)); } else if ((iw & (0b11 << 30)) == 0) { /* Instruction word is type C. */ uint8_t syllable = extract_syllable_from_word(iw, state->active_thread->sc); - state->active_thread->sc++; // TODO: Should this be part of extract_syllable_from_word()? After all, incrementing the PC is done in fetch_instruction_word(). - uint32_t pre_execution_pc = state->active_thread->pc; // TODO: This is so we can catch JMP/JSR/etc subroutines that need the SC to be reset to zero. + state->active_thread->sc++; + /* The following variable allows us to catch JMP/BRZ instructions that */ + /* jump to a new PC and need the SC reset. */ + uint32_t pre_execution_pc = state->active_thread->pc; execute_syllable(state, syllable); if (state->active_thread->pc != pre_execution_pc) { - // Jumped to a new address, so prepare to execute a new instruction word. + /* Jumped to a new address, so prepare to execute a new instruction word. */ state->active_thread->sc = 0; state->hack->resume_word = false; } else if (state->active_thread->sc >= SPW) { - // Just executed the last syllable in this word, time to follow the PC to the next word. + /* Just executed the last syllable in this word, follow the PC to the next word. */ state->active_thread->sc = 0; state->hack->resume_word = false; } else { - // More syllables remain to be executed in this instruction word. + /* More syllables remain to be executed in this instruction word. */ state->hack->resume_word = true; state->hack->iw = iw; } -- 2.20.1