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 X contains a positive integer value. Write a recursive procedure with the label "fib" that calculates the Xth entry of the Fibonacci sequence, FX In essence, your procedure should implement the following C function:
int fibint n
if n
return
else if n
return
else
return fibn fibn
The argument will be provided in X Leave the result, FX in X
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 nonzero registers through x Remove any calls to debug: for final submission.
code:
fib:
SUB SP SP #
STR LRSP
CMP X #
BEQ basezero
CMP X #
BEQ baseone
SUB X X #
MOV X X
BL fib
MOV X X
SUB X X #
BL fib
ADD X X X
LDR LRSP
ADD SP SP #
RET
basezero:
MOV X #
LDR LRSP
ADD SP SP #
RET
baseone:
MOV X #
LDR LRSP
ADD SP SP #
RET
ERROR SS BELOWYour code must pass all tests to earn any marks. Try again.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
