created 05/17/2016

# Chapter 11 Programming Exercises

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

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

```## Mysterious vanishing pattern
##
.text
.globl  main

main:
ori     \$10,\$0,0x2BAD    # put a pattern into \$10
xori    \$10,\$10,0xF3C5   # mess it up with a xor
xori    \$10,\$10,0x????   # what immediate operand will
# restore the original pattern in \$10 ?
```

Replace `0x???` with some immediate operand. Run the program by pushing F10 to single step. Check the register display after each step. Find the bit pattern to use in the third instruction that will return `\$10` to its original pattern.

## *Exercise 2

Create a source program containing the following lines.

```## Sixteen bit negative
##
.text
.globl  main

main:
ori     \$11,\$0,0x0001    # put a one into a register \$11
ori     \$10,\$0,0x0009    # put a nine into \$10
xori    \$12,\$10,0xFFFF   # reflect the bits
# Add positive nine and negative nine
```

Complete the program as described in the comments. The goal is to create a 16-bit negative nine in register `\$11` and then to add the positive and negative together. Do you end up with a 16-bit zero?

```   * == easy program