Question: Code this in ARM Use the following algorithm to calculate the nth number in the fibonacci sequence. Inputs will be from 1 to 1 0

Code this in ARM
Use the following algorithm to calculate the nth number in the fibonacci sequence. Inputs will be from 1 to 10. Input of 1 should return 0, input of 2 should return 1, input of 3 should return 1, input of 4 should return 2, input of 5 should return 3, and so on.
procedure fib(argument: n)
return fib(n-2)+ fib(n-1)
You must use this argument. Yes, I know every caution you've been given to NEVER use such an algorithm. This is an exercise in understanding recursion and calling procedures in assembly language.
If you use a loop or an equivalent to a case/switch table, your score on the assignment will be 20/100.
Requirements and Specifications
Your input cannot be stored as a global variable at any point. This means you cannot store it at a data section address, even when accepting them from scanf; they must be returned from scanf on the stack.
X19-X27 are global variables. You may not use X19-X27 in your recursive function. If you want, you may use X19-X27 in your main function. You can use any registers you want to in your main function.
A recursion procedure requires:
Allocate stack space
Save the return address and argument on the stack
Recursively call procedure with BL
Unwind the stack by restoring the return address and arguments and deallocating stack memory
If the code is not recursive, i.e. uses a loop or a the equivalent of a case/switch table, your score will be 20/100.
Hints and Warnings
You must put the local values and return address on the stack before any bl call, and restore the argument and the return address after the bl call.
Skeleton Code:
.section .data
input_prompt : .asciz "Please enter a number betwen 1 and 10
"
input_spec : .asciz "%d"
fib : .asciz "%d
"
oob_mess : .asciz "Input is out of bounds
"
.section .text
.global main
main:
# branch to this label on program completion
exit:
mov x0,0
mov x8,93
svc 0
ret

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 Databases Questions!