Lab 03
Lab 03
Name:
Kevin Bradshaw
Objective
The objective of this lab is to make you comfortable with MIPS control instructions by
writing, running, and debugging several complex programs.
Pre-requisite
Before starting with this lab, you should be familiar with MIPS control instructions as well
as QtSpim.
Control Instructions
As you know, the PC points to the current instruction; however, for efficiency reasons, the
PC is actually updated to the next instruction before the current instruction has completed
1
its execution. This means that the offset used in computation of PC-Relative addressing is
actually relative to the next instruction instead of the current one. The assembler in SPIM
hides this complexity from the user when it computes offsets in instructions, but you can
see this if you examine the instructions it creates.
1. Enter the following code into a file named lab3-1.s and run it using QtSpim. Use it
to answer the questions below:
. text
. globl main
1
2
3
main : l i
$a1 , 10
add $t0 , $ z e r o , $ z e r o
loop :
beq $a1 , $ z e r o , f i n i s h
add $t0 , $t0 , $a0
sub $a1 , $a1 , 1
j
loop
f i n i s h : addi $t0 , $t0 , 100
add $v0 , $t0 , $ z e r o
4
5
6
7
8
9
10
11
(a) Step through the program and find the branch instruction. Locate the value of
the 16-bit branch address and fill in Table 1.
Tab. 1: Branch Instruction Address (when delayed branches is disabled)
Instruction
Address field in instruction Target Address
(16 bits)
beq $5, $0, 16
0040002c
0x00400038
(b) Step further through the program and find the jump instruction. Locate the
value of the 26-bit jump address and fill in Table 2.
Tab. 2: Jump Instruction Address (when delayed branches is disabled)
Instruction
Address field in in- Address field shifted Target Address
struction (26 bits)
left by 2 bits (28 bits)
j 0x00400038
Save your file as lab3-2.s, and make sure you comment the code.
(b) What is the value of UIN before and after executing the code:
Variable
UIN
19
Save your file as lab3-3.s, and make sure you comment the code.
Demonstrate your program to the TA; .
Hint: A common mistake here is to forget that when addressing words in memory,
any word will be located 4 bytes after the previous word, not 1.
Deliverables
Submit completed copy of this lab manual.
Include the following in a compressed file (.zip format) to your TA:
The source code for all .s files.
Logfiles containing state after running all .s files.