Answered step by step
Verified Expert Solution
Question
1 Approved Answer
. section . data input _ prompt: . asciz Please enter a number between 1 and 1 0 input _ spec: . asciz
section data
inputprompt: asciz "Please enter a number between and
inputspec: asciz d
fib: asciz d
oobmess: asciz "Input is out of bounds
section text
global main
main:
Print greeting and ask for n between
ldr xinputprompt
bl printf
sub sp sp # Allocate stack space for input bytes aligned to bytes
Read inputted number
ldr xinputspec
mov x sp Use stack space to store input
bl scanf
Check for out of bound input
ldr xsp Load the inputted number from stack
Compare if value inputted is less than
cmp x #
blt checkOutOfBounds
Compare if value inputted is greater than
cmp x #
bgt checkOutOfBounds
Calculate Fibonacci and print result
mov x x
bl recurse
Print the result
ldr xfib
bl printf
b exit
checkOutOfBounds:
ldr xoobmess
bl printf
b exit
basecase:
mov x #
ret
basecase:
mov x #
ret
recurse:
subs x x #
BGT recurse
cmp x #
beq basecase
cmp x #
beq basecase
Allocate stack space for call with n
sub sp sp #
str xsp #
str xsp
sub x x #
bl recurse
Load result from fibonaccin into x
str xsp #
ldr xsp
ldr xsp #
add sp sp #
sub x x #
bl recurse
add x x x
ret
exit:
mov x #
mov x #
svc #
It is a fibonacci sequence procedure fibargument: n
return fibnfibn
should return base case
should return base case
should return
should return
should return
should return
should return
should return
should return
should return
For some reason the program is printing the "Please enter a number"... then automatically printing "Input is out of bounds and quitting" I think that is my error. Should I have a seperate fibonacci function and then calling the recurse? How so
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started