Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Here is the c + + code for the procedure. ( This is simply meant to help you understand the assignment!! ) { cout 0
Here is the c code for the procedure. This is simply meant to help you understand the assignment!! cout endl; cout & "Please input a positive number" endl;else printFunn ; return;Requirements and Specifications
Your inputs n cannot be stored as a global variable at any point. This means you cannot store them at a data
section address, even when accepting them from scanf; they must be returned from scanf on the stack.
XX are global variables. You may not use XX in your recursive function. If you want, you may use XX
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
Hints and Warnings
You must put the argument and return address on the stack before any bl call, and restore the argument and the
return address after the bl call. This includes every printf call and every recursive call.
Here is my code so far, it works if you input any negative but the positive doesnt work or
section data
inputnumber: asciz "Please enter a number:
inputspec: asciz d
printnum: asciz d
error: asciz "Please input a positive number
section bss
variable: skip
section text
global main
main:
Print Input statement
ldr xinputnumber
bl printf
sub sp sp #
Recieve input
ldr xinputspec
add x sp #
bl scanf
Check if input is negative
ldr wsp #
cmp w #
blt inputerror
bl recurse
b exit
recurse:
sub sp sp #
str wsp #
str wsp #
cmp w #
beq zeroinput
ldr xprintnum
bl printf
sub w w #
bl recurse
ldr xprintnum
ldr wsp #
bl printf
ldr wsp #
add sp sp #
ret
zeroinput:
ldr xprintnum
bl printf
ldr wsp #
add sp sp #
ret
inputerror:
ldr xerror
bl printf
b exit
exit:
Exit syscall
mov x
mov x
svc
ret
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