created 05/17/2016

Chapter 10 Programming Exercises

For these programming exercises, use only those instructions that have been discussed so far in these notes:

ori addu

In the Simulator/Settings/MIPS menu of SPIM set Bare Machine ON, Accept Pseudo Instructions OFF, Enable Delayed Branches ON, Enable Delayed Loads ON, Enable Mapped I/O OFF, Load Exception Handler OFF.

Run the programs by single stepping (pushing F10). Observing the results in the SPIM Int Regs window. Check the Registers menu that the registers are displayed in HEX.

*Exercise 1

Start with the source file for the program discussed in this and the previous chapter:

## Program to add two plus three 
        .globl  main

        ori     $8,$0,0x2       # put two's comp. two into register 8
        ori     $9,$0,0x3       # put two's comp. three into register 9
        addu    $10,$8,$9       # add register 8 and 9, put result in 10

Modify the program so that it puts a 1 in register $1, a 2 in register $2, a 3 in register $3, and so on up to register $12 (or higher if you wish). Run the program by pushing F10 to single step. Check the register display after each step.

Notice that in the QtSpim display the machine instructions of this program are loaded into memory starting at address 0x400000, the beginning of the text segment of memory.

Click here to go back to the main menu.

*Exercise 2

Create a source program containing the following lines.

##  Put data into the data segment

        .word   0               # put two's comp.  zero into beginning of data segment.
        .word   1               # put two's comp.  one into data segment.
        .word   2               # put two's comp.  two into data segment.
        .word   3               # put two's comp.  three into data segment.
        .word   4               # put two's comp.  four into data segment.

Load the program into QtSpim and look at the data segment starting at address 0x10000000. There are no machine instructions in this program so there is nothing to run. Notice that fullwords (4 bytes) are used for each integer. QtSpim memory can be displayed using binary, decimal, or hex using the menu under the "Data Segment" tab at the top. Choosing a display option merely changes the characters used to display what is in memory. Of course, the contents of memory remains unchanged.

Change several of the data in your program to large decimal values (say, 2435681). Load the program. If memory is displayed in hex, the hex equivalent of the decimal values will be displayed.

Click here to go back to the main menu.

   * == easy program
  ** == moderately easy program
 *** == harder program
**** == project

End of Exercises