Department of Information Technology

Exercise 1 : Introduction to SPIM

Goal : Get comfortable with the MIPS processor simulator: SPIM.

SPIM in short

SPIM is described in appendix A.9, page A-38 in Patterson, Hennessy (the whole appendix is also available on on-line). The described version here is XSPIM, which runs under X-windows. You can download SPIM for Unix/Linux, DOS or Windows.

Assignments :

Question 1 : You need first to copy ex1.s. The file contains the program to be run. Open it with a text editor and try to understand what it does.

Question 2 : Start XSPIM by writing xspim on the command prompt. The new window is divided into different parts. On the top part, you will find the processor registers; under, there are a number of buttons used to input commands to SPIM. Under these buttons, there is the Text Segment where you can see the machine code stored in the memory. Under the Text Segment, you can find the Data Segment which displays the data stored in the memory. You can follow what is happening when you run the program in the window that appears under the Data Segment. Notice that you can scroll through both the Data and the Text segments. (if you don't find the command xspim, or if it does not seem to work, try with /it/sw/misc/bin/xspim)

Question 3 : Begin with reseting the memory and the registers with the clear button. You can check that you have indeed cleared both of them.

Question 4 : To load a program click on load. Find ex1.s and click on assembly file.

Question 5 : Look at the text segment. You can see the addresses to the left, followed to the right by hexadecimal code of the machine instructions and finally followed by the same machine instructions in text format. To the right, you can see the equivalent assembly code instructions. You may notice that the assembly code is not identical to the machine instruction. The reason is that MIPS has uses the, so called, pseudo instructions. These are several lower level machine instructions represented by one assembly instruction. For example, at the addresses 0x00400020 and 0x00400024 you can see the two machine instructions lui $1, 4097 and lw $3, 0($1). The sequence of these two machine codes correspond to the assembly instruction lw $3, n1($0).

Question 6 : Let's look at the data segment now. What is the word stored at the address 0x10010000? what base is used to represent it? on which address can you find the word 0x00000017? what is stored at the address 0x10010008?

Question 7 : What values do R3 and R4 have?

Question 8 : Start the program . Click on run. You can see from which address the program is starting. Click on ok.

Question 9 : What do registers R3 and R4 contain now?

Question 10 : Which values have changed in the data segment? what are the new values?

Question 11 : We follow now the program execution. reset again the memory and the registers. Reload the file ex1.s. It is important that you do so, this allows you to follow the effects of running the program.

Question 12 : Set breakpoints in the program. Click on breakpoint. We will set three breakpoints: the first one with the label main in the program (look in the code), and after that a globally defined label, so you can write main in the square and click on add. Click now on "list" to check that the breakpoint has been set, in this case a text will appear in the bottom part of the window specifying in which address the breakpoint has been set. Look at the text segment: which instruction is at that address? (It is also the starting point for the program. The code appearing between the address 0x00400000 and the main label is a code used by the simulator to start the program execution.)

Question 13 : Now we want to add two more breakpoints: one of them in front of the instruction add $4, $4, $3. Search in the text segment for the address containing that instruction. What is this address? set a breakpoint there. Set another breakpoint in front of the next instruction. Which address does that breakpoint have? you can check with "list" to verify that the breakpoints are there.

Question 14 : Start the program. It will stop at the first breakpoint. What is stored in the registers R3 and R4? what is the value of PC? (PC is in the upper left corner.)

Question 15 : Continue the execution by clicking on the button with the same name. The execution stops now at the next breakpoint. what values does registers PC, R3 and R4 have?

Question 16 : Continue the execution. What values does registers PC, R3 and R4 have at the last breakpoint?

Question 17 : Try removing a breakpoint. Use list to check that the breakpoint was actually removed.

Question 18 : Reset the memory and the register and load again the program. We will follow what happens in the memory and the registers when stepping through the program. Click on step. the number of steps indicates the number of instructions SPIM will execute at each step. Run with an instruction per step. When you click on step, the program will execute one instruction. Further down in the window, you can see the instruction that has been just executed. PC contains (as usual) the address to the next instruction (to be executed). Continue clicking on step until PC contains the address 0x00400020, the program starts from there. Continue after by stepping through the program and following what happens in the registers and the memory.

Question 19 : Try to write some stuff: under print you can indicate global symbols. Down you can see which global symbols are defined in the program, in this case it is only main. what is contained in the memory addresses 0x10010000 - 0x10010010?

Question 20 : Clean the memory and the registers. Reload the program again. You will now make some changes directly in the memory in a way that the program will add 35 and 16 instead. Use the set value command to put the new values in the memory (numbers can be written in decimal). Run the program and control the result.

You can find the answers here.

Updated  2007-01-26 11:43:16 by Noomene Ben Henda.