SPIM Documentation

Get SPIM from the SPIM Home Page
Related Documentation is Available in the CD under Tutorials


A brief overview of the SPIM simulator is provided here. More information is available at the SPIM website and the on the CD associated with the text.

What is SPIM?

  • SPIM is the instruction set originally of the MIPS R2000/3000 series of microprocessors
  • The instruction set is representative of ISAs of processors designed since 1984 and of the core of modern microprocessors including the X86
  • SPIM is a public domain simulator is available¬†from sourceforge (see above).
  • A very nice Quick Reference Guide to SPIM

The SPIM Registers

  • The 32 registers are numbered $0 – $31
  • $0 is hardwired to the value 0
    • has been found to be useful to have readily available
    • you cannot write to register $0
  • There are several other special registers such as the program counter (PC)
  • Each register also has symbolic name, for example $t0 or $at. See the class notes or text for the complete set of pneumonics.
  • Until you become familiar with the SPIM registers use only registers $t0-$t9 and $s0-$s7
  • Use symbolic names rather than real values to avoid clashing with special uses of a register, for example register $28 ($gp) is initialized to a special address in the data segment

Input/Output Instructions

  • The interface to the screen and keyboard is through a group of registers and a special instruction: the syscall instruction
    • this instruction wakes up the system programs which are privileged and can interface to the keyboard and screen
    • the system program looks to $v0 for a code to determine what function needs to be performed
    • the system program uses $a0 for data it needs (e.g., printing a number to the screen) or as the destination of data (e.g., data being read from keyboard input)
    Service Code Arguments Result
    print integer 1 $a0 = integer
    read integer 5 integer in $v0
    print string 4 $a0 = string addr
    read string 8 $a0 = buffer $a1 = length
  • Examples

Using Labels

  • Absolute values of addresses are difficult to keep track of
  • We would rather deal with names or labels
  • Instructions or data directives can be labeled
    • the value of the label is the address of the corresponding memory location
    • this label can be used in other instructions in lieu of the actual numerical value of the memory address
  • Examples

Immediate Instructions

  • Such instructions are useful when we know the values of one of the operands
  • Examples: addi, lui, li, la

Instruction Types

  • Pseudoinstructions vs. native instructions. The former provide ease of programming and are translated by the assembler to native instructions that are interpreted by the hardware.
  • Some instructions may have to be translated into sequences of simpler instructions, for example when using labels in instructions since labels are themselves 32 bit quantities
  • Register $at0 ($1)
  • Onto the first SPIM program!

Writing SPIM Programs

  • Develop the algorithm
  • Perform register allocation
  • Perform memory allocation
  • Programs write themselves!
Question, comments or problems with this page to Sudhakar Yalamanchili