# 1 Objectives

Following completion of this lab you should be able to:

• Call and pass arguments to procedures in MIPS programs.
• Return from procedures.
• Discuss register allocation strategies.
• Save and restore registers.
• Correctly manage the stack.

# 2 General

• Get a copy of the question sheet to edit (Word doc version)

• Be sure to follow the MIPS procedure calling conventions as described in your book (Section 2.8 and Appendix A.6).

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

• MARS also provides a small set system calls to make input and output easier. We've been using a system call to exit our programs. test7.asm uses system calls to print integers and strings. See SYSCALL functions available in MARS and page A-44 of your text for additional information on the available system calls.

# 3 Sorting an Array

• NOTE: You may not use the 's' registers for this portion of the lab.
1. Pull your repository. Open the files lab03/p7/p7-loop.asm and lab03/p7/p7-swap.asm in MARS.

2. In a previous lab, you worked with a program for swapping the maximum element of an array with the last element. Extract your code for "swapping the maximum value of an array with the last element of the array". You'll need all the code between the label p5: and the 'jr'. Don't copy the label or the 'jr'.

If you have not already addressed the issue discussed in the last step of "Finding the Maximum" in lab 3, you'll need to do so now.

3. Add your code to p7-swap.asm in the spot indicated below the label SwapMaxWithLast:.

4. Modify your swap code so that it complies with the documentation and specifications in p7-swap.asm. Note, SwapMaxWithLast is a procedure which takes 2 arguments - the location (address) of an array of words in memory and the length (in words) of the array - and order matters. Be sure your code conforms with the MIPS procedure calling conventions (see pages A-22-A-33 of your text). Specifically, you will need to:

1. Get the address of "A" from an argument register rather than doing a "la" on a label.

2. Get the value of "N" from an argument register rather than loading it from memory.

# 7 Turning It In

Submit the answers to the questions contained in the lab guide using the question sheet via gradescope, only 1 per team (make sure all team member's names are included). In gradescope you are able add your team members names to the submission, make sure you do so. When you are prompted to indicate where the "code question" is on the answer sheet, just select the first page of the assignment, you DO NOT upload code to gradescope.

Lab code will be submitted to EVERY team member's git repository.