Question: 3. Write a recursive assembly subroutine that calculates the Fibonacci number. Fibonacci numbers are those that follow a special sequence lhke below 0. 1, 1,
3. Write a recursive assembly subroutine that calculates the Fibonacci number. Fibonacci numbers are those that follow a special sequence lhke below 0. 1, 1, 2, 3. 5. 8. 13. 21 34, 55, N Fibonacci number can be calculated with the following formula EN- 0 EN-1 F (N - 1) FIN- 2) otherwise The pseudo code of Fibonacci number function is like below unsigned int out-0 unsigned int N-5 2: unsigned int fib (unsigned int n 4: if n 1) returnni 7: 8: return fib (n-1) fib (n-2) int main (void) 10: outfib (N) while(2) 12: 13: Follow the instructions below . Create a new project and add a new assembly file "rec fibonaccis to the project. . Define two unsigned integer variables out, and N in DATA area. Initialize the variables with the specified values in the above code. Use nyData as DATA area's nane Define a function . main and Fib in CODE area. Use myCode as CODE area's . In main function, a. Load the value of N from memory and pass it to Fib function as an input parameter in RO. b. Get the return value from Fib function and store it to out variable in memory c. For the while loop in line 12, use stop B stop as in the lecture slide. In Fib function, The function should run recursively as shown in the pscudo code. Use as many registers as needed. But, you should carefully preserve them by using stack as learned from the lecture. Return the calculation result in RO a. b. c
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
