We will be using SPIM, a MIPS simulator, in order to learn assembly programming. The current version of SPIM is "QtSPIM", aka SPIM using the Qt cross-platform application GUI framework:
Download a pre-packaged version of SPIM for Linux that uses the Qt GUI framework: (If you are running an older 32-bit Linux installation, change 64 to 32 below)
unix> wget https://sourceforge.net/projects/spimsimulator/files/qtspim_9.1.22_linux64.deb
Install the QtSPIM package:
unix> sudo dpkg -i qtspim_9.1.22_linux64.deb
To launch QtSPIM:
unix> qtspim &
After launching QtSPIM, the main window should appear as shown below.
There are three primary sections contained within this window: The Register panel, Memory panel, and Messages panel.
Register Panel
The Register panel (shown below) shows the contents of all the MIPS registers. There are two tabs in this panel: one for the floating point registers and one for the integer registers. The integer registers include general purpose registers (R1-R31), along with special purpose registers such as the Program Counter (PC).
Memory Panel
The Memory panel has two tabs: Data and Text. The Text tab shows the contents of the Program memory space. From left to right, this includes:
The Data tab shows the contents of the Data memory space. This includes the variables and array data you create, along with the stack content.
Messages Panel
The Messages panel displays messages from QtSPIM to the user.
A variety of MIPS example programs are available to you. Start with the first program - example1.asm - by downloading it to your computer.
Load your first program by selecting File -> Reinitialize and Load File. (Recall that the new Ubuntu "Unity" GUI doesn't show the top-of-screen menubar until you mouse over it). This clears the register space and resets the simulator. (Otherwise, you could load and run several programs in a row on the same machine state.)
You can scroll down in the Text pane to see that the assembly code has been loaded into Program memory space. In this case, the first instruction is at memory location 0x00400024 . (Why doesn't it start at memory address zero? The program starts with the function main(), but there is some code that runs before main).
Now that the program has been loaded, you can run a simulation of the assembly instructions. You have three choices:
Step through the complete program, figure out what it does, and make sure you understand how the QtSPIM environment works.