Lab 4 - Assembly Practice
To learn to run assembly programs and use the xspim interpreter.
Running Assembly programs
Assembly programs go in text files with a
.s extention. The
program must start with the label "__start:" (two underscores) and end with
the instruction "done".
xspim is a version of
spim that runs on the X windows
graphical user interface, as opposed to
spim's console interface.
You can run
spim remotely, but you will have to refer to the
spim documentation to find the equivalent commands.
on the command line. (The ampersand causes the program to run in the
background). Then, use the load button to load in your .s file. The set buttons
can be used to set the register values, and the program can then be executed
using the run or step button. The register values will change in the top frame.
- A short MIPS program
Write a piece of MIPS code that, given values in
$s1, puts into the
$tk registers the following:
$t0 = $s0
$t1 = $s1
$t2 = $t0 + $t1
$t3 = $t1 + $t2
$t7 = $t5 + $t6
In other words, for each register from
it stores the sum of the previous two $t register values. The
$s1 registers contain the initial values.
Don't set the value of
$s1 in your code.
Instead, learn how to set it manually with
Copy the lab directory over from ~cs61c/labs/lab04
- Debugging a MIPS program
Debug the loop in the program in lab4a.s. It is meant to
copy integers from memory address $a0 to memory address $a1, until it reads a
zero value. The number of integers copied (up to, but not including the zero
value), should be stored in $v0.
- Compiling from C to MIPS
The file lab4b.c is a C version of the program in the
previous part of the lab. Compile this program into MIPS code using the command:
MIPSgcc -S -O3 -fno-delayed-branch lab4b.c
The -O3 option turns on optimization. The -S option generates assembly code.
Don't worry about the delayed branch option for now; we will revisit this topic
again when we talk about pipelining.
The above command should generate assembly language output for the C code.
Find the assembly code for the loop that copies sources values to destination
values. Then, for the registers $a0, $a1, $v0, and $v1 from part 2, determine
what registers gcc used to store the corresponding value. (For example, $a0 was
used to store the source address of integers to be copied. What register is
used for this purpose in the gcc output?)