Question: . section . data input _ prompt : . asciz Please enter a number betwen 1 and 1 0 input _ spec : .

.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:
//print greeting and ask for n between 1-10
ldr x0,=input_prompt
bl printf
sub sp, sp, #4
//read inputted number
ldr x1,=input_spec
mov x0, sp
bl scanf
//check for out of bound input
ldr x2,[sp]
//compare if value inputted is less than 1
cmp x2,1
blt checkOutOfBounds
//compare if value inputted is greater than 10
cmp x2,10
bgt checkOutOfBounds
mov x0, x2
bl recurse
ldr x0,= recurse
bl printf
b exit
checkOutOfBounds:
ldr x0,= oob_mess
bl printf
b exit
base_case_1:
mov x0, #0
ret
base_case_2:
mov x0, #1
ret
recurse:
cmp x0, #1
b.eq base_case_1
cmp x0, #2
b.eq base_case_2
//allocate stack space for call with n-1
sub sp, sp, #16
str x30,[sp, #8]
str x0,[sp]
sub x0, x0, #2
bl recurse
//load result from fibonacci(n-1) into x2
str x0,[sp, #8]
ldr x0,[sp]
ldr x30,[sp, #8]
add sp, sp, #16
sub x0, x0, #1
bl recurse
add x0, x0, x29
ret
# branch to this label on program completion
exit:
mov x0, #0
mov x8, #93
svc #0
It is a fibonacci sequence procedure fib
(argument: n)
return fib(n-2)+fib(n-1)
1should return 0(base case)
2should return 1(base case)
3 should return 1
4 should return 2
5should return 3
6should return 5
7should return 8
8should return 13
9should return 21
10should return 34
For some reason the program is printing the "Please enter a number"... then automatically printing "Input is out of bounds and quitting"

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!