a)
Assume the following C code. Translate both functions to MIPS using the caller callee conventions as presented in class. Do not translate the print statement:
int main(){
int g=0; /*global variable */
int u= fib(5);
printf("%d",g); /*print the number of times you called fib */
}
int fib(int n){
g+=1 /*increase global variable every time you have a funtion call */
if (n==0) return 0;
else
if (n==1) return 1;
else
return fib(n-1) +fib(n-2);}
b)What is printed by the previous program? For arbitrary n what is the formula that gives g (i.e. How many times if fib(n) being called for arbitrary n)? Is fib effective? Explain
c)Rewrite a for Loop definition for fib and translate it to MIPS code.
d) Can you achieve the same effectiveness with a recursive definition? Give a fib implementation that behaves like a for loop given that your compiler optimizes tail call elimination(hint: the new function should have 3 arguments) .Give the MIPS code produced in such a compiler.