Docsity

MIPS Code Generation for a Recursive Power Function - Prof. Laurence Alan Herman, Assignments of Computer Science

Toggle sidebar
bg1
CMSC 212 MIPS practice problem Fall 2009
Write MIPS code that a compiler could generate for the program below. You might want to write the
code for the main program before that of the function.
#include <stdio.h>
int power(int x, int y) {
if (y == 1)
return x;
else return x * power(x, y - 1);
}
int main() {
printf("%d\n", power(2, 5));
printf("%d\n", power(3, 4));
printf("%d\n", power(1, 8));
return 0;
}

Partial preview of the text

Download MIPS Code Generation for a Recursive Power Function - Prof. Laurence Alan Herman and more Assignments Computer Science in PDF only on Docsity!

CMSC 212 MIPS practice problem Fall 2009

Write MIPS code that a compiler could generate for the program below. You might want to write the code for the main program before that of the function.

#include <stdio.h>

int power(int x, int y) { if (y == 1) return x; else return x * power(x, y - 1); }

int main() { printf("%d\n", power(2, 5)); printf("%d\n", power(3, 4)); printf("%d\n", power(1, 8)); return 0; }