Write an MIPS procedure of calculating the n-th term of the Fibonacci sequence F (n)
Someone please help me by showing how to do this.
Write an MIPS procedure of calculating the n-th term of the Fibonacci sequence F (n).
F(n) is defined as below:
When n = 0, F (n) = 0
When n = 1, F (n) = 1
Otherwise, F (n) = F (n-1) + F (n-2)
however,you have to use following algorithm which is clear but very inefficient:
int fib(int n) {
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
return fib(n-1) + fib(n-2);
}
Write an MIPS procedure of calculating the n-th term of the Fibonacci sequence F (n).
F(n) is defined as below:
When n = 0, F (n) = 0
When n = 1, F (n) = 1
Otherwise, F (n) = F (n-1) + F (n-2)
however,you have to use following algorithm which is clear but very inefficient:
int fib(int n) {
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
return fib(n-1) + fib(n-2);
}
0