The Execute Menu

Execution of an assembly language program in CPU Sim involves the following steps:

  1. load into CPU Sim the machine on which your program is to be run,
  2. initialize the contents of the registers to the values you desire,
  3. create or open a text file that contains the assembly program to be run,
  4. assemble and load the program into the memory of your simulated machine,
  5. run the program.

You have the choice of running the program without interruptions (other than interruptions caused by errors in your code) by choosing "Clear, assemble, load & run", "Assemble, load & run", or just "Run" from the Execute menu (see Figure 13), or you can step through the program one machine instruction or one microinstruction at a time by using debug mode.


Figure 13. The Execute menu.

Debug Mode

The Debug Mode menu item causes the debug toolbar to be displayed if CPU Sim is not currently in Debug Mode (and vice versa).

Assemble

The "Assemble" menu item checks your code for legality. If the code is legal, nothing happens. If the code is illegal, an error message will appear and the offending line of assembly code will be highlighted for you to edit. Note that the code in any text window must be saved to a file before it can be assembled. If you try to assemble it before saving it, a dialog box will ask you to save it first. Note also that CPU Sim does not create executable files or object files. Every time you want to run a program, that program must be reassembled.

Assemble & load

The "Assemble & load" menu item assembles your code and, if it is legal, loads the assembled (machine) code into the simulated machine's memory. The RAM into which the code is loaded is not first cleared (set to 0), and so the only memory locations that are changed are those into which the new code is loaded. If you want to clear the rest of RAM, you need to do so first by choosing the appropriate menu item from the Execute menu.

Note 1: You can use the Options Dialog in the Execute menu (discussed below) to specify which RAM is to be loaded with the machine code and what starting address is to be used. To do so, navigate to the "Loading" tab in the "Options" Dialog.

Note 2: When you load the assembled code into RAM, all the code is treated as one long string of bits that is loaded into the cells of RAM from left to right. Therefore, for example, if you have two 8-bit instructions as your code and RAM has cells of size 5 bits, then the first 15 bits of the 16 bits of code will be loaded into three cells and the remaining code bit will be loaded as the high order bit in the next cell.

Assemble, load & run and Clear, assemble, load & run

The "Assemble, load, & run" menu item is a convenience item that is equivalent to choosing the "Assemble & load" menu item followed by the "Run" menu item. Similarly, the "Clear, assemble, load & run" menu item is a convenience item that is equivalent to choosing the "Reset everything" menu item followed by "Assemble, load & run".

Run

The "Run" menu item causes the machine to begin execution. The program will always begin execution with the first microinstruction of the fetch sequence. The program will stop when one of the following events occurs:

  1. One or more condition bits that are designated as halt bits have their value set to 1.
  2. The user selects "Stop" from the Execute menu.
  3. The user selects "Cancel" when an input dialog is displayed.
  4. An error occurs.

Stop

The "Stop" menu item causes the currently executing program to halt. This menu item is particularly useful if the program gets into an infinite loop.

Note that this menu item is one of several ways to stop a program in an infinite loop. An alternative is to set the value of a condition bit to 1 by manually editing the contents of the register containing the condition bit. Or you can edit the contents of RAM to get the program to execute a halt instruction or to crash. If the program is repeatedly asking for input from a dialog box, you can select the Cancel button in the dialog. If the program is repeatedly asking for input from the console, you can just press enter instead of entering data.

Reset Everything

The "Reset everything" menu item causes all registers, register arrays, and RAMs to be cleared (that is, set to their default values). It also resets execution so that it will start with the fetch sequence, and resets all the IO channels. If the IO channel is a file, the file is closed. Note that you can also clear any individual register or cell of RAM manually by editing its contents in the register or RAM windows.

Options

The "Options" menu item brings up a dialog box where the user can edit the IO Connections, Highlighting, Loading, Punctuation, and the indexing of bits in a register. To learn more about this dialog box, go to The Options Dialog.