Lab 1 Introduction To MIPS Lab
Lab 1 Introduction To MIPS Lab
Lab 1 Introduction To MIPS Lab
5 Points
CS 281 Systems Architecture I
Overview
In this lab you will trace through a simple MIPS program using the SPIM simulator. The
SPIM simulator is described in Appendix A and can be obtained from
http://www.cs.wisc.edu/~larus/spim.html.
Objective
To become familiar with the SPIM simulator and MIPS assembly and machine language.
Readings
! Appendix A Section 9
! Tutorials on BBLearn
Outline
In this lab, you will trace through a simple MIPS program and record all of the state
changes (i.e. changes to registers, including the PC, and the stack). You will also list the
instructions that are executed and the corresponding machine code.
Things You Need to Know
! Instructions
" add rd, rs, rt; rd = rs + rt
" sub rd, rs, rt; rd = rs - rt
" lw rt, addr(rs); rt = Mem[addr + rs]
" sw rt, addr(rs); Mem[addr + rs] = rt
" jr rt; PC = rt [jump register]
" jal addr; [jump and link] PC = addr
! Register conventions and the use of the stack
" Registers a0,...,a3 are used to pass arguments to a procedure. Registers v0 and v1
are used to hold the results of a function call. Registers t0,...,t7 are temporary
registers that need not be saved by the called procedures. Registers s0,...,s7 are
stored registers that must be saved by the called procedure.
" The top of the stack is pointed to by the stack pointer (register $sp). By convention
the stack grows down (i.e. a push is performed with a subtraction). The stack is
used to save information and create space for local variables when a procedure is
called. The behavior of procedure calls is compatible with a stack - a procedure is
not finished until all of the procedures it calls are finished, and so on ...
5. Step through the program one instruction at a time using the single step command in
the Simulator menu. You should step until the main program is entered (see the jal
main instruction). After main is entered, you should step through until main is
completed. Write down each instruction that is executed and record any change in a
register or the stack. Also record the machine code for each instruction along with its
address. You can save the contents of the SPIM windows by using Save Log File in the
File menu. After saving the log file, you can cut and paste instructions and their
corresponding machine code. Indicate the format and contents of the fields of the first
add and lw instructions you encounter.
What To Hand In
Please submit the following:
1. A copy of the console window after running the sum.asm program. Use Printscreen in
Windows to copy and then paste the picture of the console window to a word
processor. Alternatively, you can save a log file of the QtSpim session (this is done
using the Save Log File command in the File menu). Once the log file is saved, you can
open it with any editor you want and can cut and paste from there. Note that you can
copy and paste from the QtSpim windows. (1 point)
2. A trace of the execution of sum.asm. Include all of the information asked for in Step 5.
(3 points)
3. A description file that thoroughly details all testing you have done, discusses your
results and mentions any difficulties you may have encountered. Please follow the
specifications for a description file. (1 point)