MIPS playground
Write MIPS assembly and run it in your browser, with nothing to install: an editor like the lab’s Notepad++, with colours and autocomplete, and a simulator like QtSpim, with the registers, the text and data segments, the console and step-by-step execution. Inside it runs SPIM, the same simulator that powers QtSpim, so addresses, pseudo-instructions and error messages are the ones you will see in the IC1 exam.
Loading the MIPS environment…
How to use it
- Editor and Simulator: the two tabs at the top, like Notepad++ and QtSpim in the lab. You write in the Editor and press Load, which does the same as Reinitialize and Load File: it clears memory and registers and loads your program from scratch. If there is a syntax error, it appears in Messages and the line is marked in the editor.
- Run (F5) takes the program to the end, to a breakpoint or until it asks for input. Step (F10) executes a single instruction. Pause stops a program that takes too long, and Stop takes it back to the start.
- Breakpoints: in the Text tab, click the left margin of an instruction to set or clear one (a coral circle appears). Run stops just before that instruction.
- Registers (Int Regs and FP Regs) and memory (Text and Data) look like QtSpim; the registers an instruction has just changed are shown in another colour. Hex / Dec picks the base and Kernel also shows the kernel code and data.
- Console: what your program prints. When a read syscall (5, 8 or 12) waits for data, an Input line appears for you to type it.
- Hints: colours, autocomplete with templates such as
print_stringorread_int, an explanation of each step and the current line marked in the editor. You can turn them off one by one to practice as in the exam. - Look: the sun button switches to the light look, with the white of Notepad++ and QtSpim, and the moon goes back to dark. It is remembered in this browser, like your code. With the other buttons you download your
.s, upload one of yours, copy a link to share it (the code travels inside the link) or go back to the example.
How it compares with QtSpim
- The same: the program starts with the start-up code at 0x00400000 and your
mainat 0x00400024; data goes at 0x10010000; pseudo-instructions are expanded the same way (laintoluiandori); and errors and exceptions say the same, such as «Unaligned address in store». - A SPIM quirk: for some syntax errors the message says one line too many («line 4» when the mistake is on line 3), because SPIM detects the error when it reads the end of the line. QtSpim does exactly the same; this environment also marks the right line in the editor.
- What changes: the editor and the simulator are on the same page (in the lab they are two programs) and there is a single file. The stack pointer (
$sp) starts at a different address than on your computer, because it depends on where it runs (it also changes from one computer to another in QtSpim). And if a program reaches ten million instructions without finishing, the environment stops and warns you: it is almost always an infinite loop. - Versions: the core is SPIM 9.1.20 (BSD licence, by James R. Larus). QtSpim 9.1.24, the current version, and 9.1.12 in the lab assemble and run the course programs the same way.
Paste this into the editor, press Load and go step by step watching $t0 and $t1:
.data
lives: .word 3
msg: .asciiz "Lives: "
.text
.globl main
main: la $t0, lives # $t0 = the address of the datum
lw $t1, 0($t0) # $t1 = the datum
li $v0, 4
la $a0, msg
syscall
li $v0, 1
move $a0, $t1
syscall
li $v0, 10
syscall
Practice with it
- The guides to install QtSpim, use QtSpim and Notepad++ for MIPS: what you learn there works the same here.
- If you also study other languages, there are the Python, Java and C playgrounds, all in Playgrounds.
