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

Exercise 3 -- Procedures

Sorting an Array

  1. Modify your version of p5.asm from Exercise 2 so that it is a procedure named SwapMaxWithLast which takes 2 arguments - the location (address) of an array of words in memory and the length (in words) of the array. Be sure your code conforms with the MIPS procedure calling conventions (see pages A-22-A33 of your text).

  2. Download p7.asm to your local hard disk and examine it using your favorite text editor.

  3. Add your procedure to the bottom of p7.asm in the location indicated.

  4. Modify main so that it calls SwapMaxWithLast a single time with A and N as arguments. What output do you expect when you run p7.asm?

  5. Start PCSPIM and load your modified version of p7.asm.

  6. Run p7.asm. Is the actual output what you expected?

  7. Modify main so that it calls SwapMaxWithLast $\texttt{N}-1$ times and with each successive call the length of the array passed is decreased by 1. In pseudocode:

      for (i=N; i>1; i--) {
        SwapMaxWithLast(A, i);
      }
    

    What output do you expect when you run p7.asm?

  8. Run p7.asm. Is the actual output what you expected?

  9. If SwapMaxWithLast needed to return a value how would that be accomplished?

  10. What changes would you need to make if SwapMaxWithLast needed more than 4 arguments?

  11. What changes would you need to make if SwapMaxWithLast called another procedure?

  12. Describe the changes you would make to create a sort procedure which is called in main and which in turn calls SwapMaxWithLast.



J.P. Mellor 2004-09-20