Install QtSpim — Windows, Linux and Mac, the lab settings and your first MIPS program in 10 minutes (and the day QtSpim couldn’t see my file)

First assembly lab of IC1. I write my program in Notepad, save it as suma.s, open QtSpim, File > Load File… and the folder is empty. No sign of the file. I save it again, close, open, nothing. In the end the classmate next to me shows me what was going on: Notepad had saved it as suma.s.txt (Windows hides the second extension) and QtSpim only shows .a, .s and .asm files.

In this guide you install QtSpim (the MIPS simulator used in the IC1 labs and in the practical exam), set it up exactly as in the lab and run your first program. When you finish, carry on with how to use QtSpim, which explains every panel, and with Notepad++ for MIPS, the editor you write the programs in.

What QtSpim is and why we use it in IC1

QtSpim is a simulator of the MIPS32 processor (the R2000 from the course notes): it reads a program written in assembly language, loads it into a simulated memory and runs it instruction by instruction while it shows you the registers and the memory. It doesn’t compile anything or produce an .exe: everything happens inside the simulator.

Why not program a real MIPS directly? Because your computer has an x86 or ARM processor, which understands other instructions. QtSpim plays the part of a “pretend MIPS processor” and, on top of that, lets you see what you can’t see on a real processor: the value of every register after every instruction.

In IC1 you use it in three places:

  • In the assembly lab sessions (the ones in the second half of the course).
  • In the practical exam: about 90 minutes programming MIPS assembly with QtSpim, and the program has to work with any data.
  • In the theory exam you don’t have it in front of you, but knowing how to read its text panel (address, machine code and instruction) helps with the instruction-encoding questions.

QtSpim has no text editor. The program is written in another program (in the lab, Notepad++) and QtSpim only loads and runs it. That’s why the workflow is always the same:

The lab workflow with QtSpimFour steps: write the program in Notepad++, save it with a .s extension, load it in QtSpim with Reinitialize and Load File and run it with F5; the output appears in the Console window and, if there is an error, you go back to the editor.From the editor to the console: the lab workflow1 · You writesuma.s in Notepad++2 · You saveCtrl+S, .s extension3 · You loadReinitialize and Load4 · You runRun/Continue (F5)ConsoleMinutes in total: 160Error or odd output? Fix it in the editor and repeat 2 → 3 → 4
QtSpim has no editor: every change means saving in Notepad++ and loading again in QtSpim.

Before you start: what you need

  • A computer with Windows 10/11, Linux or macOS. QtSpim is tiny: any laptop you take to class will do.
  • Permission to install programs (Windows will ask for administrator confirmation).
  • A plain-text editor to write the programs. I recommend Notepad++ with MIPS colours (guide here); for this first test any editor will do, except Word, which adds formatting and breaks the file.

Step 1 — Download QtSpim

QtSpim is free and open source (BSD licence). It’s written by James Larus and you download it from the project’s official page on SourceForge: spimsimulator.sourceforge.net, in the downloads section. Pick the file for your system:

SystemFile (version 9.1.24, August 2023)How to install it
Windows 10/11QtSpim_9.1.24_Windows.msiDouble-click and “Next”
Linux (Ubuntu, Debian…)qtspim_9.1.24_linux64.debsudo apt install ./qtspim_9.1.24_linux64.deb
macOSQtSpim_9.1.24_mac.mpkg.zipUnzip and open the package

The IC1 campus recommends 9.1.12 (from 2013), which is the one on the lab virtual machine. 9.1.24 is the latest and has the same menus, panels and shortcuts: a program that works on one works on the other. If you want to play it safe for the exam, practice with whichever you have installed and take a look at the lab one on the first day.

Step 2 — Install it

On Windows

  1. Open QtSpim_9.1.24_Windows.msi.
  2. Accept the licence and keep the folder it suggests: it installs into C:\Program Files (x86)\QtSpim.
  3. When it finishes you’ll have QtSpim in the Start menu. Pin it to the taskbar: you’ll open it a lot.

If Windows shows “Windows protected your PC”, click More info > Run anyway: SmartScreen warns about programs that aren’t downloaded very often. For exactly that reason, download it only from the official page on SourceForge, never from download sites.

On Linux

On Ubuntu or Debian, from the folder where the .deb is:

sudo apt install ./qtspim_9.1.24_linux64.deb
qtspim &

On Fedora (the IC2 distribution) there’s no QtSpim package, but there is spim, the terminal version of the same simulator: sudo dnf install spim and then spim -file suma.s. It runs programs just the same, only without windows. To practice with panels and stepping, the easiest option on Fedora is QtSpim on Windows or the lab virtual machine.

On macOS

Unzip QtSpim_9.1.24_mac.mpkg.zip and open the package. If macOS says it’s from an unidentified developer, right-click the package > Open. With Homebrew, brew install --cask qtspim also works.

Step 3 — First launch: the windows

When you open QtSpim two windows appear: the main one and a smaller one, Console, which usually ends up behind it. This is how the main window is laid out:

The QtSpim windowsDiagram of the QtSpim main window with the registers panel on the left, the text and data panel on the right, the messages at the bottom, the menu bar and buttons at the top, and the separate Console window.What you see when you open QtSpimQtSpimFile Simulator Registers Text Segment Data Segment Window Helptoolbar: load, reload, Run, Pause, Stop, Single StepInt Regs / FP RegsPC = 400024HI · LOR8 [t0] = 0R10 [t2] = a0…Text | Data[00400024] 3c081001 lui $8, 4097[00400028] 3c011001 lui $1, 4097[0040002c] 8c290010 lw $9, 16($1)[10010000] 45 30 60 25 (Data)SPIM Version 9.1.24 … (simulator messages)ConsoleMinutes in total: 160123451 Processor registers2 Text and data segments3 Messages (load errors)4 Console: input and output5 Menus and buttons
The console is a separate window: if you cannot see it, Window > Console.

And this is what it really looks like, with a program already loaded and the Data tab open (the first time, the right-hand panel will be almost empty):

QtSpim 9.1.24 main window with the integer registers panel on the left, the Data tab with the user data segment on the right and the version messages at the bottom
QtSpim 9.1.24 on Windows with the example program loaded: registers (Int Regs), data (Data) and messages.

Each area has its detailed guide in how to use QtSpim. For now, keep three things in mind:

  • Left: the processor registers (R0 to R31 with their name in brackets: [t0], [a0]…).
  • Right: the loaded code (Text tab) and the data memory (Data tab).
  • Bottom: QtSpim’s messages. If the program has a typo, the warning appears here, not in the console.

Looking for the program’s output in the main window. What your program prints (and what you type when it asks for a value) goes in the Console window. If you can’t see it, Window > Console.

Step 4 — The lab settings

QtSpim can simulate a “bare” MIPS, like the real processor, or one with conveniences for programming. In IC1 we work with the Simple Machine configuration, which is the default. Check it in Simulator > Settings, MIPS tab:

QtSpim Settings dialog, MIPS tab: Accept Pseudo Instructions ticked, Bare Machine, Enable Delayed Branches, Enable Delayed Loads and Enable Mapped IO unticked, Load Exception Handler ticked
The lab configuration: only Accept Pseudo Instructions and Load Exception Handler ticked (Simple Machine button).
OptionIn IC1What it does
Bare MachineNoSimulates the “bare” MIPS: no pseudo-instructions and with delayed branches and loads
Enable Delayed BranchesNoThe instruction after a branch always runs, whether it branches or not (as on the real pipelined MIPS)
Enable Delayed LoadsNoThe value of an lw isn’t available until one instruction later
Enable Mapped IONoMemory-mapped input/output (not used in the labs)
Accept Pseudo InstructionsYesLets you write li, la, move, blt… and QtSpim swaps them for real instructions when loading
Load Exception HandlerYesLoads the exception handler and the code that calls your main

If you ever change something and don’t know how to go back, click Simple Machine and leave Load Exception Handler ticked. The other tab, QtSpim, only changes the look (fonts and colours of the panels and the recent-files list):

QtSpim Settings dialog, QtSpim tab: recent file list length 4, Quiet option and black Courier font on a white background for the panels
QtSpim tab: it only affects the look. A bigger font helps a lot on a laptop.

If the panel text feels small, in the QtSpim tab click the “…” next to Font and go up to 11 or 12 points. It doesn’t change anything about the program and the machine code becomes much easier to read.

Step 5 — Your first program

We’re going to add up the minutes you studied on four days (45, 30, 60 and 25) and print the total. You don’t need to understand every instruction yet: what matters today is the path of writing, saving, loading and running. Copy it into your editor:

# suma.s: adds up the study minutes of four days
        .data
minutes: .word 45, 30, 60, 25      # minutes of each day (4-byte words)
days:    .word 4                   # how many days there are
msg:     .asciiz "Minutes in total: "
        .text
        .globl main
main:   la   $t0, minutes          # $t0 = address of the first day
        lw   $t1, days             # $t1 = days left to add
        li   $t2, 0                # $t2 = running total
loop:   beq  $t1, $zero, end       # if there are no days left, leave the loop
        lw   $t3, 0($t0)           # $t3 = minutes of the current day
        add  $t2, $t2, $t3         # total = total + minutes
        addi $t0, $t0, 4           # move on to the next word (4 bytes)
        addi $t1, $t1, -1          # one day fewer
        j    loop
end:    li   $v0, 4                # syscall 4: print a string
        la   $a0, msg
        syscall
        li   $v0, 1                # syscall 1: print an integer
        move $a0, $t2
        syscall
        li   $v0, 10               # syscall 10: end the program
        syscall

In two sentences: the .data part reserves the data in memory (the four days, how many there are and the message) and the .text part is the code. The loop goes through the four numbers with $t0 pointing at each one, adds them up in $t2 and at the end three system calls (syscall) print the message and the number and end the program.

  1. Save it as suma.s (in Notepad++, File > Save As, type “All types”). Check that it really ends in .s.
  2. In QtSpim, File > Reinitialize and Load File, find the folder and choose suma.s. Look at the dialog’s filter, bottom right: Assembly (\.a \.s \.asm)*. Anything without one of those extensions doesn’t show up (the problem in the anecdote).
QtSpim Open Assembly Code dialog on Windows with the files suma.s and suma-con-tildes.s and the Assembly (*.a *.s *.asm) filter
QtSpim’s dialog only shows .a, .s and .asm: a suma.s.txt wouldn’t appear here (Windows in Spanish).
  1. If there are no errors, the Text panel fills up with your instructions and the messages at the bottom say nothing new. If there’s an error, QtSpim shows it in an Error window and repeats it in the messages at the bottom, with the line number (more in common problems).
  2. Click Run/Continue (the triangle on the toolbar or F5). The Console window shows:
Minutes in total: 160

Check it by hand: 45 + 30 + 60 + 25 = 160. And look at the registers panel: the ones that changed are in red, and R10 [t2] is a0, which is 160 in hexadecimal (10 × 16 = 160).

QtSpim after running the program: the Console window shows the total of 160 minutes and the registers that changed are in red in the registers panel, with R10 t2 equal to a0
After F5: the output in Console and the registers that changed in red (the values are in hexadecimal; the capture is of the Spanish version of the program).

QtSpim shows the registers in hexadecimal by default. If you prefer decimal while you’re learning, Registers > Decimal. In the exam it pays to be able to read both.

Final check: is everything ready?

  • Does QtSpim open and do the messages at the bottom say SPIM Version 9.1.x?
  • In Simulator > Settings > MIPS, are only Accept Pseudo Instructions and Load Exception Handler ticked?
  • Does your suma.s appear in the Reinitialize and Load File dialog? (if not, check the extension)
  • With F5, does the console say Minutes in total: 160?
  • Do you know where to look if something fails? (the messages at the bottom, with the line number)

If you answered yes to all of them, you now have the lab environment at home.

Common problems and how to fix them

SymptomLikely causeFix
The file doesn’t appear when loadingIt was saved as suma.s.txtIn File Explorer, View > Show > File name extensions and rename it to suma.s
spim: (parser) syntax error on line 14 of file …A typo on that line (for example $to instead of $t0)Go to that line in the editor; the ^ underneath marks where it stopped understanding
The following symbols are undefined: endA misspelt label, or a syntax error before it that cut the loading shortFix the syntax error that appears higher up first
You press F5 and nothing showsThe console is behind the main windowWindow > Console
The program never endsA loop with no way out (you forgot to move the counter on)Simulator > Pause or Stop, and look at the registers (you’ll see how in how to use QtSpim)
You change the program and QtSpim still does the old thingYou didn’t save, or you used Load File without reinitialisingSave in the editor and always use Reinitialize and Load File

Using Load File twice in a row. That option adds the program to what’s already in memory, so the second time all your labels exist twice and QtSpim complains with an Error window: spim: (parser) Label is defined for the second time on line 8 of file …, pointing at your main:. To reload after a change, Reinitialize and Load File (it wipes everything and loads from scratch).

What next?

You now have QtSpim installed, set up as in the lab and with a program that works. Next:

  1. Notepad++ for MIPS: the lab editor with colours and autocompletion for MIPS (I’ll give you the file ready to import).
  2. How to use QtSpim: what every number in the text panel means, how to run step by step, set breakpoints and read the memory.
Keep goingAll Tools articles

Did this article help you? Here is how you can support SergioLearns →