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
p7.asm to your
local hard disk and examine it using your favorite text editor.
Add your procedure to the bottom of p7.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 p7.asm?
Start PCSPIM and load your modified version of
p7.asm.
Run p7.asm. Is the actual output what you expected?
Modify main so that it calls SwapMaxWithLast 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?
Run p7.asm. Is the actual output what you expected?
If SwapMaxWithLast needed to return a value how would
that be accomplished?
What changes would you need to make if SwapMaxWithLast
needed more than 4 arguments?
What changes would you need to make if SwapMaxWithLast
called another procedure?
Describe the changes you would make to create a sort
procedure which is called in main and which in turn calls
SwapMaxWithLast.