Question: . 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:
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 KEEPS AUTOMATICALLY PRINTING OUT "Input is out of bounds" and ending the program
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
