Addressed minor TODOs in simulator.c
authorAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 9 Jul 2021 01:31:36 +0000 (18:31 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 9 Jul 2021 01:31:36 +0000 (18:31 -0700)
hacks/NEDsim/simulator.c

index 9c63b67..73623dc 100644 (file)
@@ -172,9 +172,6 @@ ned_instruction_add(struct NEDstate * state)
 static void
 ned_instruction_shift(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) {
     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);
         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) {
         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) {
             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 {
             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;
         }
             state->hack->resume_word = true;
             state->hack->iw = iw;
         }