Due Thursday, November 15

15 points

For this assignment you will write a MAL subprogram for computing the
greatest common divisor of two integers.
Also, you will write a short main program that will be used in
conjunction with `xspim`

and `spim`

to test the
subprogram.

The gcd subprogram should mimic the following C function:

/** gcd(n1, n2) returns the greatest common divisor of n1 and n2. */ int gcd(int n1, int n2) { if (n2 == 0) { return n1; } return gcd(n2, n1%n2); }

You must implement this function recursively to get full credit. See MIPS Subprograms for instructions on writing recursive subprograms. If you take care with planning the use of registers the code won't be too difficult.

The main program should prompt for two integers, print their greatest common divisor, and repeat until the user enters a negative number for one of the integers.

Do not use "m" or "M" as names of memory variables. This will result in unpredictable behavior, especially with regard to input.

You may lose points if your code is not well commented.
Your `gcd`

function comments should clearly document its
calling convention and its use of registers.
See Assembly Language Comments
for suggestions on writing comments.

You will not get debugging help from the TA or myself if you do not have good comments. I recommend writing the function comments before writing the code. You will likely make fewer mistakes and have an easier time debugging if you do.

Turn in a typescript showing the
contents of your MAL code file along with a `spim`

session that
shows the execution of your testing code.
In this session, you should enter the following pairs of integers:

- 0, 17 (answer 17)
- 17, 0 (answer 17)
- 8, 13 (answer 1)
- 13, 8 (answer 1)
- 24, 42 (answer 6)
- 132, 96 (answer 12)
- 195, 120 (answer 15)
- 377, 610 (answer 1)