The factorial.s MIPS program implements the following C++ program:
int fact ( int n ) {
if (n<=1) return 1;
else return n*fact(n-1);
};
main () {
int i, res;
while (true) {
cout << " Number? ";
cin >> i;
if (i<=0) break;
res = fact(i);
cout << "The factorial is: " << res << endl;
};
};
To run the factorial program on gamma, type /public/cse/5317-501/spim/spim and then (inside spim) type load "/public/cse/5317-501/factorial.s" and then run. (If you are using omega, use 4305 instead of 5317.)
Last modified: 1/15/98 by Leonidas Fegaras