Question: Assume that X 0 contains a positive integer value. Write a recursive procedure with the label fib that calculates the X 0 th entry of

Assume that X0 contains a positive integer value. Write a recursive procedure with the label "fib" that calculates the X0th entry of the Fibonacci sequence, F(X0). In essence, your procedure should implement the following C function:
int fib(int n){
if (n==0)
return 0
else if (n==1)
return 1
else
return fib(n-1)+ fib(n-2)
}
The argument will be provided in X0. Leave the result, F(X0), in X7.
Note: You must implement the function using recursion! Iterative solutions will not pass!
For convenience of debugging, a procedure labeled "debug:" has been defined which will print the values of all non-zero registers (through x29). Remove any calls to debug: for final submission.
code:
fib:
SUB SP, SP, #16
STR LR,[SP]
CMP X0, #0
BEQ base_zero
CMP X0, #1
BEQ base_one
SUB X1, X0, #1
MOV X0, X1
BL fib
MOV X2, X7
SUB X0, X1, #1
BL fib
ADD X7, X7, X2
LDR LR,[SP]
ADD SP, SP, #16
RET
base_zero:
MOV X7, #0
LDR LR,[SP]
ADD SP, SP, #16
RET
base_one:
MOV X7, #1
LDR LR,[SP]
ADD SP, SP, #16
RET
ERROR SS BELOWYour code must pass all tests to earn any marks. Try again.
Assume that X 0 contains a positive integer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!