CSSE 232 - Computer Architecture I
Rose-Hulman Institute of Technology
Computer Science and Software Engineering Department

Exercise 2 -- DECISION INSTRUCTIONS

Looping

  1. Download p4.asm to your local hard disk and examine it using your favorite text editor.

  2. Start PCSPIM and load p4.asm.

  3. Where are main, loop, exit, N and Sum located (i.e. what address)? Hint: Simulator:Display Symbol Table might be useful.

  4. Before you run the program, calculate the number of instructions that will be exectued and the final value of Sum. Note: Appendix A of Patterson and Hennessy has lots of useful information about MIPS and SPIM.

  5. Set a break point at main and single step to the end of the program. How many instructions were actually executed? What is the final value of Sum?

  6. Modify p4.asm so that it will work correctly if N is equal to 0. Be sure to test your modifications to make sure they work.

  7. How many instructions does your modified program execute when N is equal to 5? Can this number be improved? If so, how? Hint: If you added 5 instructions, you can do better.

  8. Will your modified program work if N is less than 0?

Finding the Maximum

  1. Download p5.asm to your local hard disk and examine it using your favorite text editor.

  2. Reinitialize PCSPIM and load p5.asm.

  3. Run p5.asm. What is the value of max and maxindex at the end of the program? Are they what you expect?

  4. Comment out sll $t5, $t2, 2 and rerun the program. What happens? Why?

  5. Modify p5.asm so that the largest element of A is swapped with the last element of A. Be sure to adequately test your modified program. Hint: change the elements and size of A.

  6. If you repeatedly apply your modified program to the subarrays of A from 0 to $N-i$ where $i$ is the number of times you've applied your program, what is the final state of A?

  7. Like p4.asm this program doesn't work if N is equal to 0. It is brittle in other ways as well. For example, what happens if all of the elements are less than -1? How could you address this?

Rotating an Array

  1. Download p6.asm to your local hard disk and examine it using your favorite text editor.

  2. p6.asm uses the .asciiz assembler directive. See page A-47-A-49 and A-14-A-15 of your text for details.

  3. SPIM also provides a small set system calls to make input and output easier. We've been using a system call to exit our programs. p6.asm uses system calls to print integers and strings. See page A-44 of your text for a complete list of the available system calls.

  4. Reinitialize PCSPIM and load p6.asm.

  5. Run p6.asm. What is displayed in the console window?

  6. Modify p6.asm to treat V as a circular array and rotate its contents one position to the right. Rotate the array in place. Specifically, $\textrm{V}(i)$ moves to $\textrm{V}(i+1\
\textrm{mod} N)$. After performing the rotation, your program should print the string ``The rotated array:'' followed by the elements of the rotated array, each preceded by a single space character.



J.P. Mellor 2004-09-08