[go: up one dir, main page]

0% found this document useful (0 votes)
37 views12 pages

01 Laboratory Exercise

This document provides instructions for a laboratory exercise using a CPU simulator. The objectives are to familiarize students with the CPU simulator environment and how to use it. The document describes the main components of the simulator interface, including the CPU instruction memory, registers, program stack, and buttons for creating and running programs. It provides step-by-step procedures for creating a new program and adding CPU instructions to it using the simulator software.

Uploaded by

Superman Ako
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views12 pages

01 Laboratory Exercise

This document provides instructions for a laboratory exercise using a CPU simulator. The objectives are to familiarize students with the CPU simulator environment and how to use it. The document describes the main components of the simulator interface, including the CPU instruction memory, registers, program stack, and buttons for creating and running programs. It provides step-by-step procedures for creating a new program and adding CPU instructions to it using the simulator software.

Uploaded by

Superman Ako
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

H0023

Laboratory Exercise #1
Familiarization with the Simulator
Objectives:

At the end of the exercise, the students should be able to:


 familiarized with the CPU simulator environment, and
 use CPU simulator

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:

• CPU instruction set


• CPU registers
• Different ways of addressing instructions and data in instructions

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:

1. Create a CPU program


2. Enter CPU instructions in the program
3. Run the program
4. Observe and control simulations

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:

• CPU Instruction memory


• Special CPU registers
• CPU (general purpose) registers
• Program stack
• Program creation and running features

Laboratory Exercise #1 *Property of STI


Page 1 of 12
H0023

Figure 1.1 CPU-OS Simulator Main Window

 CPU Instruction Memory View

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.

Laboratory Exercise #1 *Property of STI


Page 2 of 12
H0023

Figure 1.2 CPU Instruction Memory View

 Special CPU Registers View

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

Figure 1.3 Special CPU Registers View

Laboratory Exercise #1 *Property of STI


Page 3 of 12
H0023

 CPU Registers View

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.

Figure 1.4 CPU Registers View

Laboratory Exercise #1 *Property of STI


Page 4 of 12
H0023

 Program Stack View

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.

Figure 1.5 Program Stack View

 Program List View

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

Figure 1.6 Program List View

Laboratory Exercise #1 *Property of STI


Page 5 of 12
H0023

 Program Creation

Create Program Tab

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.

Figure 1.7 Create Program Tab

Add Program Instruction Tab

This tab is composed of different buttons that are used to modify an instruction in adding program.
These buttons are the following:

• ADD NEW… - This button is used to add a new instruction.


• EDIT… - This button is used to edit the selected instruction.
• MOVE DOWN/ MOVE UP – This button is used to move down or up the selected instruction.
• INSERT ABOVE…/INSERT BELOW… - This buttons is used to insert a new instruction
above or below the selected instruction respectively.

Figure 1.8 Add Program Instruction Tab

Procedures:

Activity 1 Creating a CPU Program that contains Instructions

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.

Laboratory Exercise #1 *Property of STI


Page 6 of 12
H0023

Info: The name of the program will appear in the PROGRAM LIST frame as shown in Figure 1.10.

Figure 1.9 New Program

Figure 1.10 Program List

Activity 2 Adding CPU instructions in the program

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.

Figure 1.11 Program Instructions

Laboratory Exercise #1 *Property of STI


Page 7 of 12
H0023

Figure 1.12 Instructions

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.

Laboratory Exercise #1 *Property of STI


Page 8 of 12
H0023

Figure 1.13 HLT Instruction

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.

Figure 1.13 Instruction Memory

Activity 3 Editing the Program Instructions

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.

Laboratory Exercise #1 *Property of STI


Page 9 of 12
H0023

Figure 1.14 Editing Program Instructions

Activity 4 Running the Program

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.

Figure 1.15 Program Control

Activity 5 Observing and Controlling the Simulation

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.

Laboratory Exercise #1 *Property of STI


Page 10 of 12
H0023

Figure 1.16 General Purpose CPU Registers

Activity 6 Observing/altering the Program Data

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.

Figure 1.17 Data Memory

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

Laboratory Exercise #1 *Property of STI


Page 11 of 12
H0023

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.

Activity 7 Observing/altering the Program Stack

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.

Figure 1.18 Program Stack

Activity 8 Saving and Loading the CPU Programs

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.

Figure 1.19 Save and Load

Laboratory Exercise #1 *Property of STI


Page 12 of 12

You might also like