Question
Question A) The MIPS ISA Computing a Fibonacci Number The Fibonacci number Fn is recursively defined as F (n) = F (n 1) + F
Question A)
The MIPS ISA
Computing a Fibonacci Number
The Fibonacci number Fn is recursively defined as F (n) = F (n 1) + F (n 2),
where F (1) = 1 and F (2) = 1. So, F (3) = F (2) + F (1) = 1 + 1 = 2, and so on.
Write the MIPS assembly for the fib(n) function, which computes the Fibonacci number F (n):
int fib(int n) {
int a = 0; int b = 1; int c = a + b;
while (n > 1) {
c = a + b;
a = b;
b = c;
n--;
}
return c;
}
Remember to follow MIPS calling convention and its register usage (just for your reference, you may not need to use all of these registers):
The argument n is passed in register $4.
The result (i.e., c) should be returned in $2.
$8 to $15 are caller-saved temporary registers.
$16 to $23 are callee-saved temporary registers.
$29 is the stack pointer register.
$31 stores the return address.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started