Lab 4: MIPS Calling Convention


Due Monday, October 26 at 11:59:59 PM

Goals for This Week

By the time you have completed this work, you should be able to:

Provided files: Documentation:

Step by Step Instructions

You will perform one large task for this week: properly implement the PrintReverse function in functions.asm, using the MIPS Calling convention. To this end, you may want to consult this documentation on the MIPS calling convention, as well as Section A.6 in the course textbook, before you try to implement this function.

The initial step below describes how to get the files you will need into the appropriate place.

Initial Step: Create a Directory for This Lab and Copy Over the Files

After you log in, go into your cs64 directory that you created last time:

cd cs64

Then create a new directory for this lab: lab4:

mkdir lab4

Then go into that directory.

Now copy over all of the files necessary for this week's tasks:

cp ~kyledewey/public_html/cs64/labs/4/functions.asm ~kyledewey/public_html/cs64/labs/4/partner.txt .

Note the use of the trailing . in the above command, which stipulates that the specified files should be copied into the current directory.

Implementing the PrintReverse Function

For your single task, you will implement the PrintReverse function in functions.asm using the MIPS calling convention. PrintReverse takes two arguments:

  1. The address of an array of word-long (four byte) signed integers, held in $a0.
  2. The length of the array as an unsigned integer, held in $a1.

The function should print the provided array in reverse order. For example, if given:

1 2 3

...the function should print:

3 2 1

In addition to printing out the elements in reverse order, you must call another provided function named ConventionCheck each time you print out an element. Do not implement ConventionCheck youself, or modify it in any way. On our end, we are going to use our own version of ConventionCheck while grading, so the only assumptions you can make about ConventionCheck are that it will follow the MIPS calling convention.

While we provide an array in the file, your code should work on any arbitrary array. On our end, for testing purposes we will use different arrays, so your code should work with any other valid (non-empty) array.

The main function provided in functions.asm calls PrintReverse on your behalf, and it will display the contents of the array in non-reversed order before and after calling PrintReverse.

Your output should have the format shown below. The first two lines and the last line are generated by the main function, so you do not have to implement anything to print those portions out. The lines containing the words “Convention Check” are produced by the ConventionCheck function you must call after printing each input. To help clarify which output you need to produce and which output is produced for you, output you must produce is marked in bold.

Current Array:
0 1 -1 5 32 6 -66 33 12 58 -4 64 
64
Convention Check
-4
Convention Check
58
Convention Check
12
Convention Check
33
Convention Check
-66
Convention Check
6
Convention Check
32
Convention Check
5
Convention Check
-1
Convention Check
1
Convention Check
0
Convention Check
0 1 -1 5 32 6 -66 33 12 58 -4 64

Remember to follow the MIPS calling convention while implementing your PrintReverse function. Otherwise, the program may crash hard.

Hint: Use “jal label” to call other functions, replacing label with the name of the function you want to call. For example, if you want to call the ConventionCheck function, then you ultimately need to use the following code snippet:

jal ConventionCheck

Turn in Everything Using turnin

If you partnered with someone, record the email address they are using for the class in partner.txt. For example, if your partner had the email address foo@bar.com, then the contents of partner.txt should be the following (and only the following):

Partner: foo@bar.com

If you did not partner with anyone, you do not need to (and should not) edit partner.txt.

Assuming you are in the cs64/lab4 directory you created at the beginning, you can send in your answers via the following command:

turnin lab4@cs64 functions.asm partner.txt

You may turn in the same assignment up to 100 times, which is useful if you are working on it incrementally. Note that only the last version you submitted will be graded.

Even if you did not partner with anyone, you should still turn in partner.txt, which should not have been modified.


Prepared for Computer Science 64 by Diana Franklin, with slight adaptation by Kyle Dewey.