HOMEWORK #3


Reading Assignment: Chapter 3.1 - 3.5 and Appendix A

Extra instruction to experiment with an instruction-level simulator.

 

STEP 1: Download spim.zip in your directory. Unzip to extract the two files, spimwin.exe and pgm.asm.

 

STEP 2: Save these files in a temporary directory. After downloading is completed, run spimwin.exe and install the PCSpim simulator program. Follow the instructions given on screen.

 

STEP 3: After the simulator is installed, run the simulator from START/PROGRAM/PCSpim for Windows/PCSpim for Windows.

 

STEP 4: When the simulator is started, you should see 4 windows titled "Messages", "Data Segment", "Text Segment", and "Registers". If you don't see them, click on the Window menu and select Tile.

STEP 5: Now that you have 4 empty windows in your simulator screen, click on File menu and select Open, or click on the first button right below the File menu, to open and load a file. From the open window, go to the directory where the pgm.asm file is stored and open it.

STEP 6: You should see that the Messages Window shows a message saying that the file has been successfully loaded. Then in the Text Segment Window, you will see the actual program loaded with the Program Counter (PC) attached on the left starting from [0x00400000].

STEP 7: Go to the "Simulator" on the menu bar and select the "Set value..." menu.  Set the Program counter (PC) value to 0x00400000 as shown below. 

 

 

The program will start off at PC=0x00400000 and execute a few OS related instructions and then will jump to PC=0x00400020 where the user code starts. (Scroll along the Text Segment Window and compare the code that are executed to the original code in file pgm.asm)

STEP 8: Run the program in Single Step mode. Goto Simulator menu, and select Single Step or press F10 key to advance one step. Stop when PC value gets stuck at the same address.



P1. (30 points) 

Run the program given in file pgm.asm and report:
(a) What happens to the content of register LO.
(b) What instructions are equivalent to sd $4, 32($sp).
(c) What instructions are equivalent to mul $15, $14, $14.
(d) How the contents of stack locations 0x7fffeff4 and 0x7fffeff8 in Data Segment Window vary.

Here's the key to some of the details in the SPIM simulator that you can observe when you load the pgm.asm file.  If you go through a few steps in the program, you will observe the stack being updated.  Two of the memory locations accessed by the program can be found here

P2. (20 points) 

Chapter 3, Problem 3.1.

P3. (25 points) 

Chapter 3, Problem 3.6. addi instruction adds an immediate number to a register. You may like to run the corrected version on the simulator described above.

P4. (25 points) 

Chapter 3, Problem 3.11. You may run the program on simulator and submit the debugged version of the program.