Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions

Question

9. How does one identify the essential functions of a job?

Answered: 1 week ago