Greatest Common Divisor (GCD)
=============================
The greatest common divisor (gcd) of two nonnegative integers a and b
is the largest nonnegative integer d such that d divides a and
d divides b. We use the notation gcd(a,b) to denote the greatest
common divisor of a and b. Around 300 B.C, the Greek mathematician
Euclid showed that gcd(a, b) = gcd(b, a mod b). This leads
to the following (recursive) algorithm for computing
the gcd:
int
gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b); /* % is the C notation for the mod operator */
}
void
main(void)
{
int a, b;
printf("Enter a and b: ");
scanf("%d%d", &a, &b);
printf("gcd(%d, %d) = %d\n", a, b, gcd(a, b));
}
Translate the above C code to MIPS assembly code and test your program
using the SPIM simulator. The solution requires the use of stack frames.
Follow the MIPS register conventions and do not forget to give
comments to your code.
Do not forget to give comments to your code so that (1) the teacher
(i.e., me) has an easier job of grading your program, and (2) if somebody
decides to use your program long after you have written it, he has a
chance of understanding what you exactly did.