Debug mode provides you with several tools for finding bugs in your code, including the following:
To enter debug mode, select the "Debug mode" menu item in the Execute menu. This action will cause (a) a debug toolbar to appear below the main menu (see Figure 28) and (b) a new column of checkboxes to appear on the left side of all RAM windows.
Figure 28. The debugging toolbar
The label to the left of the scroll box on the right end of the toolbar always displays the machine instruction or fetch sequence that is about to be or is currently being executed. In Figure 28 above, the fetch sequence is about to be executed. At the start of each machine cycle, the toolbar displays the fetch sequence first. The scroll box lists the microinstructions comprising the current machine instruction or fetch sequence. The microinstruction that is to be executed next is always highlighted.
Go
The "Go" button causes execution to continue without interruption until one of the following happens:
Step by Instr
The "Step by Instr" button causes the execution of one full machine cycle (a fetch sequence followed by the execute sequence of the instruction decoded by the fetch sequence). If part of a machine cycle has already been executed (for example, by means of the "Step by Micro" button or if the execution of a whole cycle was halted because of an error), then clicking this button causes the rest of that machine cycle to be executed. The name of the machine instruction currently being executed is displayed in the label to the scroll box at the right end of the toolbar.
Step by Micro
The "Step by Micro" button causes execution of one microinstruction in the current fetch or execute sequence. The name of the microinstruction to be executed is highlighted in the scroll box on the right end of the debug toolbar. After execution of the microinstruction, any values in registers that were changed by it are highlighted with a green border.
Backup one Instr
The "Backup one Instr" button causes the machine to back up to the state it was in at the beginning of the last machine cycle. You can continue backing up one machine instruction at a time all the way to the initial state of the machine when you entered debug mode.
Backup one Micro
The "Backup one Micro" button causes the machine to back up to the state it was in at the beginning of the previous microinstruction. You can continue backing up one microinstruction at a time all the way to the initial state of the machine. If you have been backing up by microinstruction and then use the "Backup one Instr" button, the machine will back up to the state it was in at the beginning of the last machine cycle. From there you can back up by machine instruction or microinstruction, or you can step forward by machine instruction or microinstruction.
Start over
The "Start over" button causes the machine to back up all at once to the initial state it was in when the user started executing the current program in debug mode using the current machine. This action also causes the IO to be flushed and reset and the control unit to be reset (to begin execution at the start of the fetch sequence). This buttons functions similarly to "Reset everything" in the Execute menu except that this button does not clear the registers and RAMs (unless they were clear when debug mode was entered).
Setting Break points in RAM windows
The column of checkboxes in the RAM windows that appears when CPU Sim is in debug mode is used for setting break points. CPU Sim will halt execution whenever a MemoryAccess microinstruction attempts to read or write to a cell of memory with a checked box. More precisely, the MemoryAccess microinstruction will be executed, the row of the RAM window with the checked box will be highlighted in red (if the RAM window is closed, it is opened automatically) and then execution will halt. At that point, you can inspect and/or change the contents of any register or RAM and continue execution or back up.
By checking the box in front of a memory cell containing a machine instruction, you can halt execution when that instruction is reached (since that instruction needs to be loaded into a register via a MemoryAccess microinstruction before it can be executed).
By checking the box in front of a memory cell containing data--for example, data on the system stack--you can halt execution when that data is read or written.
Notes