<< Assembly Unit Home

This Intro

1. Installation »
Demo (Flash - quicktime)

2. Start & Setup SPIM »

3. Run Programs »
Demo (Flash - Quicktime)

4. Create Programs »


Objectives
  • Install the Windows version of SPIM and configure it to run assembly programs.
  • Load small assembly programs in the SPIM environment.
  • Run a small assembly program in the SPIM environment.
  • Create a small assembly program

To get the most out of these pages check the learner guide. To learn more about SPIM, read the 3-page documentation.


1. Installation

  1. Download SPIM.
  2. Unzip pcspim.zip
  3. Run SETUP.EXE
<< page top

2. Start & Setup SPIM

  1. Run SPIM

    Launch SPIM

  2. Setup the simulator
    Select menu item Simulator->Settings...
  3. Check the options as in the following figure

SPIM settings

Note: these settings allow you to run programs from the textbook and class notes. More details for later.
Note: You can set your font preferences: select menu item Simulator->Set Font. Set to the smallest font you are comfortable with.
<< page top

3a. Run Assembly Programs

  1. Download sample.s - [view]
    right-click mouse, select Save Target As...
  2. Load sample.s into SPIM:
    select menu item File->Open.
  3. Initialize the program registers:
    select menu item Simulator->Set Value
    try $t2=9, $s0=7, $t4=0x00400024

    Set values sample

    later you can use better ways to input data into programs
  4. If input registers are loaded correctly screenshot, run program (otherwise return to last setp):
    select menu item Simulator->Go, or press F5,
    or click the Go button on toolbar
    Go button.
  5. Enter program command line parameters:
    simply click OK, or press ENTER (type the shown address if necessary)

    Command line dialog

  6. "Registers" window (top part) show final values of CPU registers.
    note that $t0 holds the hex value 0x00000023 (decimal 35) which is the opcode for lw.

Sample output

Problem? Simply relaod (select Simulator->Reload sample.s) and run again (back to 3a step 3 above). You may need to do that more than once.

3b. Re-run Program

Select Simulator->Reload sample.s then run as in 3a steps 3-5 above


3c. Run Program Step-by-Step

Don't forget to (re)initialize registers (Step 3a.3 above)
  1. Select menu item Simulator->Single Step, or press F10.
  2. Press F10 repeatedly until the highlight is on line
    jal 0x00400024 [main]
    this instruction jumps to your program which begins at the line labeled main:

    Step through program

    notice that registers have been initialized (see $t2 and $t4), your code starts in memory address 0x00400024, the execution bar is on the jal instruction ready to jump to the first line of your code which starts at label main:
  3. Press F10 repeatedly to step through your program.
  4. Watch CPU registers change after each step.
    in particular, watch the program counter (PC)
<< page top

4. Create Assembly Programs to Run on SPIM

  1. Type your assembly statements in a plain text editor
    for example, use Notepad (under All Programs -> Accessories)
  2. Label your first statement "main:"
    for example,
    main: add $s0,$s1,$s2
  3. Include at the end of your program
    ori $2,$0,10
    syscall
  4. Save your program file with extension .s
    for example: test.s
Tip: format your code in 4 columns to make it more readable. See sample programs in this site for examples. More on proper format.

Notepad is not the best way to create and edit programs. Use a proper source code editor instead. Here are some recommendations.

  • MIPSter (shareware) - recommended option
    feature-rich and inexpensive ($10) with a trial version available for download
    screenshot
  • Notepad++ (freeware), or the program editor from your programming course.
<< page top

What next? Start working through SPIM Exercise 0
<< Assembly Unit Home