01 Laboratory Exercise
01 Laboratory Exercise
Laboratory Exercise #1
Familiarization with the Simulator
Objectives:
Materials:
Computer with Windows XP Service Pack 2 or higher installed with CPU-OS Simulator Software
Basic Principles:
The programming model of computer architecture defines low‐level architectural components. These
components are the following:
Computer architecture also defines interaction between the components listed above. This low‐level
programming model makes programmed computations possible.
CPU-OS Simulator is an application that operates in a computer with Windows operating system. The CPU
simulator can run programs that are manually created. The following are the four stages:
The main window is composed of several views, which represent different functional parts of the simulated
processor as shown in Figure 1.1. These views are the following:
This view contains the program instructions. These instructions are displayed as sequences of
low‐level instruction mnemonics (assembler‐level format) and not as binary code. This view is done
for clarity and makes code more readable.
Each instruction is associated with two addresses: the physical address (PAdd) and the logical
address (LAdd). This view also displays the base address (Base) against each instruction. The
sequence of instructions belonging to the same program will have the same base address.
This view shows the set of CPU registers, which have pre‐defined specialist functions. These
functions are the following:
• PC: Program Counter – it contains the address of the next instruction to be executed.
• IR: Instruction Register – it contains the instruction currently being executed.
• SR: Status Register – it contains information pertaining to the result of the last executed
instruction.
• SP: Stack Pointer – This register points to the value maintained at the top of the program
stack
• BR: Base Register – It contains current base address.
• MAR: Memory Address Register – It contains the memory address currently being
accessed.
• Status bits:
o OV: Overflow
o Z: Zero
o N: Negative
The CPU register set view shows the contents of all the general‐purpose registers, which are used to
maintain temporary values as the program's instructions are executed. Registers are very fast
memories that hold temporary values while the CPU execute instructions.
This architecture supports 8 to 64 registers. These registers are often used to hold values of a
program's variables as defined in high‐level languages. Not all architectures have many registers.
Some architectures have more (e.g. 128 register) and others have less (e.g. 8 registers). In all cases,
these registers serve similar purposes.
This view displays each register's name (Reg), its current value (Val) and some additional values,
which are reserved for program debugging. It can also be used to reset the individual register values
manually which is often useful for advanced debugging. To manually change a register’s content,
select first the register then enter the new value in the text box, Reg Value, then click on the
CHANGE button in the Registers tab.
The program stack view is another area which maintains temporary values as the instructions are
executed. The stack is a LIFO (last‐in‐first‐out) data structure. It is often used for efficient interrupt
handling and sub‐routine calls. Each program has its own individual stack. The CPU instructions
PSH (push) and POP are used to store values on top of stack and pop values from top of stack
respectively.
This view is composed of different buttons that are used for your program. These buttons are the
following:
• Show Program Data Memory…
• Remove Program
• Remove All Programs
• Create Program Instance
• Delete Program Instance
Program Creation
In this tab, it is where you create a new program. To do this, enter the name of the new program in
the Program Name box and its base address in the Base Address box then click the ADD button.
The new program name you created will appear in the Program List view.
This tab is composed of different buttons that are used to modify an instruction in adding program.
These buttons are the following:
Procedures:
1. Click Start > All Programs > CPU-OS Simulator > CPU-OS Simulator to open the application.
2. Create a folder in My Documents and name it as MySimulator – [YourName].
3. Create a new program. Type MyProgram – [Your Name] as your program name in the Program
Name text box located in the program frame below the CPU instructions in memory (RAM).
4. Type in number zero (0) in the Base Address text box. Then, click the ADD button. This is shown in
Figure 1.9.
Info: The name of the program will appear in the PROGRAM LIST frame as shown in Figure 1.10.
1. Click the ADD NEW…button from the instructions frame as shown in Figure 1.11. This button will
view the CPU instructions that you can select for your created program from activity 1 as shown in
Figure 1.12.
2. Select any of the available CPU instructions for your program in the instructions window as shown in
Figure 1.12. These instructions are categorized into different groups. Select a group by clicking on a
tab. For this activity, select MOV from Op Code.
3. The selected instruction requires operand(s). The available types will be enabled under the Source
Operand and the Destination Operand frames. Enter number ten (10) in the Value of source operand.
Click the NEW button to add the instruction.
Note: You can also add multiple instructions without closing the window. Add more instructions to
your program.
4. The CPU simulator requires that the last instruction in the program should be the HLT instruction to
stop the simulation from running. Click Control Transfer tab> select HLT from Op Code> New >
Close as shown in Figure 1.13. The program is now ready to run.
Note: The instruction memory (RAM) frame is composed of the PAdd (Physical Address), Ladd
(Logical Address) and the instruction as shown in Figure 1.13.
1. Select the desired instruction from the list and use one of the editing functions (EDIT, DELETE,
MOVE UP, MOVEDOWN) to edit the selected instruction. Use the INSERT ABOVE…and the
INSERT BELOW…buttons to insert a new instruction above or below the selected instruction. The
editing program instructions are shown in Figure 1.14.
Info: A CPU program can run in two different ways, either by instruction by instruction or
automatically.
1. To run a desired instruction, select and double-click the instruction you want to run. Alternatively, you
can click the STEP button from Program Control frame (make sure the by instruction option is
selected) as shown in Figure 1.15.
2. Use the STOP button to stop the running program.
3. Use the slider control to speed up or slow down the running program.
Info: An instruction which writes or reads a register accesses the general purpose CPU registers
frame and the accessed register is highlighted.
1. The general purpose CPU registers frame shows the registers and their values as shown in
Figure 1.16. Click on the Val (value) column to change the values from decimal (D) to hex (H)
format and vice versa.
Note: To manually alter a register’s value, first select it then enter the new value in the Reg Value
field and click on the CHANGE button.
1. 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 data memory window shown in Figure 1.17. Display
this window by clicking the SHOW PROGRAM DATA MEMORY… button in the program list frame.
In this window, you can also edit the contents of the data.
Info: 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.
2. To change the values of any bytes, select the line(s) containing the bytes. Then use the information
in the Initialise Data frame to modify the values of the bytes in the selected line(s) as Integer, Boolean
or String formats. Click the UPDATE button to make the changes.
3. Check the Stay on top check box to make sure the window always stays on top of other windows
while still allowing access to other windows. Then, click CLOSE.
Info: Programs make use of the PROGRAM 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.
1. Manually push and pop data by clicking the PUSH and POP buttons.
2. Modify a stack entry by selecting it, entering the new value in the Value text box and clicking the
CHANGE button as shown in Figure 1.18.
1. To save a program, select the program from the pull down list on the program frame and click the
SAVE…button. The Save As dialog box will appear. Locate the folder that you created, then click
Save.
2. To load a saved program, click the LOAD…button. The open dialog box will appear. Locate your
saved program then click Open. These buttons are shown in Figure 1.19.