Sei sulla pagina 1di 5

PCSPIM Lab Tutorial 1

Download and install

1. Download PCSpim (file PCSpim_9.1.9.zip ) from http://sourceforge.net/projects/spimsimulator/files/


2. Unzip PCSpim_9.1.9.zip and run setup.exe to install it.

Configuration

1. Start PCSpim (hereafter shortened to "Spim")


Note for 64-bit users: The first time you run Spim it may complain about a missing exception handler
(exceptions.s). If you see this message, open Settings, look under "Load exception file", and change the
path to the following (or something similar):

C:\Program Files (x86)\PCSpim\exceptions.s

2. When PCSpim starts, it pops up a large window on your screen (see Figure 1). The window is divided
into four panes:
The top pane shows the values of all registers in the MIPS CPU and FPU.
This display is updated whenever your program stops running.

The next pane displays instructions from both your program and the system code that is loaded
automatically when PCSpim starts running. Each instruction is displayed on a line that looks like
[0x00400000] 0x8fa40000 lw $4, 0($29) ; 89: lw $a0, 0($sp)
i. The first number on the line, in square brackets, is the hexadecimal memory address of the
instruction.
ii. The second number is the instructions numerical encoding, again displayed as a
hexadecimal number.
iii. The third item is the instructions mnemonic description. Everything following the semicolon
is the actual line from your assembly file that produced the instruction.
iv. The number 89 is the line number in that file. Sometimes nothing is on the line after the
semicolon. This means that the instruction was produced by SPIM as part of translating a
pseudoinstruction into more than one actual MIPS instruction.

The third pane displays the data loaded into your programs memory and the data on the programs
stack. The addresses and data/ instructions are shown in hexadecimal format.

The bottom pane is where PCSpim writes messages. This is where error messages appear.
Figure 1

3. Create a folder named lab KT14203 in My Documents directory.

4. Open word editor (notepad, textpad or wordpad).


Tutorial 1
In this tutorial, you will learn how to store data (the value is 6) in memory, and then move the data into
a register.

1. Type these instructions into your word editor and save it as Lab1Tutorial1.s into folder lab
KT14203 you have created before.

########################
# Data segment
########################
.data
item: .word 6

########################
# Text segment
########################
.text
main: lw $t0, item # Load word into $t0 from memory[item]
li $v0, 10 # syscall number 10 will exit from program
syscall # actually exit the program

2. Load the program into PCSpim. Your program should look like the one shown below.
3. From the Text Segment, you can find the first instruction of your program (main) in memory
address 0x00400024.

4. In the Data Segment, your data initially stored in memory [0x10010000]. The hex presentation
of your data is 0x00000006.

5. In the Registers Segment, look at register $t0. The initial value for this register is 0.

6. Simulate/ run the program (press F5 key or the Go button from the toolbar). Spim will ask you
for a starting address. You should see 0x00400000 as the default. Press OK.

7. Your program will run and then stop when it reaches the exit syscall. Now, look back at register
$t0. The value has change to 6.

8. To observe step-by-step execution, reload your program (select Simulator>Reload


.\LabTutorial1.s, select Yes to reinitialize the simulator). Notice that General Registers are zero
again, and that the PC register is back at 0x00400000. This tells you the next instruction that
Spim will execute. The step-by-step execution can be observed by pressing F10. Keep pressing
F10 to step through your program slowly.

9. Now, turn to your word editor. Replace the data segment as below:

########################
# Data segment
########################
.data 0x10010004
item: .word 6

10. Repeat step 2 and step 3. Where is your data stored in the memory?
Tutorial 2

In this tutorial, you will learn how to perform arithmetic operations.

1. Type these instructions into your word editor and save it as LabTutorial2.s into folder lab
KT14203 you have created before.

########################
# Data segment
########################
.data
item1: .word 0x00000008
item2: .word 0x00000006

########################
# Text segment
########################
.text
main: lw $s0, item1 # Load word into $s0 from memory[item1]
lw $s1, item2 # Load word into $s1 from memory[item2]
add $s2, $s0, $s1 # Add ($s0) and ($s1) and keep the result in $s2
sub $s3, $s0, $s1 # Sub ($s0) and ($s1) and keep the result in $s3

sw $s2, item1 # Store ($s2) into memory[item1]


sw $s3, item2 # Store ($s3) into memory[item2]

li $v0, 10 # syscall number 10 will exit from program


syscall # actually exit the program

2. Load the program into PCSpim.

3. Simulate the program by pressing F10.

4. The result of add operation is stored in $s2 and transferred to memory a cell where item1 is
located, while the subtract operations result is stored in $s3 and transferred to a memory cell
where item2 is located.

Potrebbero piacerti anche