You are here: Home / Past Courses / Fall 2016 - ECPE 170 / Tutorials / QtSpim Tutorial

QtSpim Tutorial

Installation

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:

Install the Qt framework that SPIM requires:

unix>  sudo apt-get install qt4-dev-tools qt4-doc libqt4-help

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 http://sourceforge.net/projects/spimsimulator/files/qtspim_9.1.12_linux64.deb

Install the QtSPIM package:

unix>  sudo dpkg -i qtspim_9.1.12_linux64.deb

 

Usage

To launch QtSPIM:

unix>  qtspim &

 

Overview

After launching QtSPIM, the main window should appear as shown below.

qtsim_full_window.png

 

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).

qtspim_register_window.png

 

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:

  1. The memory address of an instruction in hexadecimal (shown in brackets)
  2. The contents of that memory address in hexadecimal. In binary form, this is the actual MIPS instruction that the processor runs!
  3. The "human-readable" assembly language instruction using the hardware register numbers (shown in bold).
  4. The assembly language program you wrote using symbolic register names and memory address symbols (shown in italics)

 

qtspim_memory_text_window.png

 

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.

qtspim_memory_data_window.png

 

Messages Panel

The Messages panel displays messages from QtSPIM to the user.

qtspim_message_window.png

 

First Program

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:

  1. Run the program from beginning to end (via the "play" Run/Continue button or F5). This is useful for seeing the final output of the program.
  2. Step through the program one line at a time (via the "123" Single Step button or F10). This is useful to see how each assembly instruction affects the machine state (i.e. memory and register values).
  3. Run the program until you reach a breakpoint (which can be set by right-clicking on any line in the Memory panel.

 

Step through the complete program, figure out what it does, and make sure you understand how the QtSPIM environment works.