Exercise 3 -- Procedures
Writing a procedure
- In file p7.asm, write a procedure Sum
that accepts two integers �a� and �c� as input parameters and returns the
sum of the two values.
- Follow MIPS register conventions.
- After you have finished your
procedure, open p7_partial.asm. Copy the main
procedure and the data segment to p7.asm.
- Run your program. Does it behave as
you expect it to?
- Fix your procedure, so that the
program works if required. You are NOT allowed to modify the data section
or �main�. Again, keep in mind that using MIPS register conventions will
fix your problem.
Sorting an Array
- 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).
- Download
p8.asm
to your local hard disk and examine it using your favorite text editor.
- Add your procedure to the bottom of p8.asm in the
location indicated.
- Modify main so that it calls SwapMaxWithLast
a single time with A
and N as
arguments. What output do you expect when you run p8.asm?
- Start PCSPIM
and load your modified version of p8.asm.
- Run p8.asm. Is the actual output what you
expected?
- Modify main so that it calls SwapMaxWithLast N-1
times and with each successive call the length of the array passed is
decreased by 1.
In pseudocode:
� �for (length=N; length>1; length--)
�� {���
�� � �SwapMaxWithLast(length, A);
�� }
What
output do you expect when you run p8.asm?
- Run p8.asm. Is the actual output what you
expected?