Instruction Manual For Programming The CPU Simulator
Instruction Manual For Programming The CPU Simulator
The CPU simulator can run programs manually created. This requires four stages:
ADD ADD #3, R02 ;adds number 3 to contents of register R02 and
stores the result in register R02.
ADD R00, R01 ;adds contents of register R00 to contents of
register R01 and stores the result in register R01.
SUB Subtract number from register; subtract register from register.
MUL Multiply number with register; multiply register with register.
DIV Divide number with register; divide register with register.
Control transfer instructions
Jump to instruction address unconditionally
JMP e.g.
JMP 100 ; unconditionally jumps to address location 100.
Jump to instruction address if less than (after last comparison)
e.g.
JLT
JLT 120 ; jumps to address location 120 if the previous comparison
instruction result indicates that CMP operand 2 is less than CMP
operand 1 (i.e. the N status flag is set). Also see CMP instruction.
Jump to instruction address if greater than (after last comparison)
JGT
e.g.
JGT 25 ;jumps to address location 25 if the previous comparison
instruction result indicates that CMP operand 2 is greater than CMP
operand 1 (i.e. flags Z and N not set). Also see CMP instruction.
Jump to instruction address if equal (after last comparison)
e.g.
JEQ
JEQ 1000 ; jumps to address location 1000 if the previous
comparison instruction result indicates that the two CMP operands
are equal (i.e. the Z status flag is set). Also see CMP instruction.
Jump to instruction address if not equal (after last comparison)
e.g.
JNE
JNE 220 ; jumps to address location 220 if the previous comparison
instruction result indicates that CMP operand 2 is less than CMP
operand 1 (i.e. the N status flag is set). Also see CMP instruction.
Subroutine instructions
MSF This instruction is required to set up a subroutine call (see below)
Jump to subroutine address
e.g. To call a subroutine starting at address location 1000 use the
CAL following sequence of instructions
MSF ; always needed just before the following instruction
CAL 1000 ; will cause a jump to address location 1000
Return from subroutine
e.g. The last instruction in a subroutine must always be the following
RET
instruction
RET ; will jump to the instruction after the last CAL instruction.
System instructions
SWI Software interrupt (used to request OS help)
Halt simulation. This must be the last instruction.
HLT e.g.
HLT ; stops the simulation run (not the simulator itself)
Comparison instruction
CMP Compare number with register; compare register with register
e.g.
CMP #5, R02 compare number 5 with the contents of register R02
CMP R01, R03 compare the contents of registers R01 and R03
Note:
If R03 = R01 then the status flag Z will be set; if R03 > R01 then
none of the status flags Z and N will be set; if R03 < R01 then the
status flag N will be set.
Input, output instructions
IN Get input data (if available) from an external IO device
Output data to an external IO device
e.g. to display a string starting in memory address 120 (decimal) on
OUT console device do the following (operand 2 = 0 for console output)
OUT 120, 0 ;the string is in address location 120 (direct addressing)
OUT @R02, 0 ;register R02 has number 120 (indirect addressing)
e
Fig. 1 – New program frame
Enter the program’s name in the Program Name text box, e.g. MyProgram. Enter a number in
the Base Address text box (suggest to use 0 in this case). Next click theADD button. The name of
the program will appear in the PROGRAM LIST frame (see Fig. 2)
In the PROGRAM INSTRUCTIONS frame the ADD NEW…button is enabled. Click this button to view the
CPU instructions. One can select for the program created above as in Fig.4
One can observe the outcomes of different buttons on the program Instruction tab.
The instruction will appear in CPU program memory area as shown in Fig. 5 below. The CPU
simulator requires that the last instruction in the program should be the HLT instruction (this
instruction stops the simulation from running). This is included in Fig. 5. The program is now
ready to run
Each entry in the INSTRUCTION MEMORY view includes the following information:
PAdd (Physical Address),LAdd(Logical Address)and the instruction. One can view the
information by pointing the cursor on respective headings.
Once the program instructions are entered they can be edited. To do this, select the desired instruction
and use one of the editing functions (EDIT,DELETE,MOVE UP,MOVEDOWN) shown in Fig. 6 to edit the
selected instruction. Use the INSERTABOVE…and the INSERT BELOW…buttons to insert a new
instruction above or below the selected instruction
Removing the program
A CPU program can be removed by clicking the REMOVE PROGRAM button shown in Fig. 7.
Once the program is removed it is no longer available and is lost. However you can save it so
that you can re-load it at a later time (see Fig.12).
Running the program
A CPU program can run in two different ways:1) instruction by instruction, 2) automatically in one go. To
run a desired instruction by itself, first select it as in Fig. 5 and double-click it. Alternatively, you can click
the STEP button shown in Fig. 8 (make sure the by inst.option is selected). Use the STOP button to stop
the running program. Use the slider control to speed up or slow down the running program.
The CPU instructions that access that part of the memory containing data can write or read the
data accessed. This information is available in the memory pages window shown in Fig. 10
above. You can display this window by clicking the SHOW PROGRAM DATA MEMORY… button
shown in Fig. 7 above. In this window you can also edit the contents of the data.
The LAdd column shows the starting address of each line in the display. Each line of the display
represents 8 bytes of information, so the LAdd numbers are incremented by 8 for each line
down the display. Columns B0 through to B7 contain bytes 0 to 7. The Data column shows the
displayable characters corresponding to the 8 bytes (hence 8 dots). Those bytes that
correspond to non-displayable characters are shown as dots. The data bytes are displayed in
hex format only.
To change the values of any bytes, first select the line(s) containing the bytes. Then use the
information in the Initialize Data frame to modify the values of the bytes in the selected line(s)
as Integer, Boolean or String formats. You need to click the UPDATE button to make the
change.
Check the Stay on top check box to make sure the window always stays on top of other
windows while still allowing access to the windows below it.
Observing/altering the program stack:
Programs make use of thePROGRAM STACK for temporarily storing important information such
as subroutine return addresses and subroutine parameters as well as other relevant
information. There are instructions that can push (PSH) data on top of this stack and that can
pop (POP) data from top of the stack to a register.
You can manually push and pop data by clicking the PUSH and POP buttons. You can also
modify a stack entry by selecting it, entering the new value in the Value text box and clicking
the CHANGE button.
Saving and loading the CPU programs:
To save a program select it from the
pull down list and click the SAVE…
button. To load a saved program click
the LOAD… button.