Question: 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 0 endl;} cout & "Please input a positive number" endl;else { printFun(n -1); 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.
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
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.
The negative number works, so does inputting zero. However when I input any n>0 it only prints 0. For example if i input 2, it prints 0,0,0,0,0 instead of 2,1,0,1,2.
Here is my code
.section .data
input_number: .asciz "Please enter a number: "
input_spec: .asciz "%d"
print_num: .asciz "%d
"
error: .asciz "Please input a positive number
"
.section .bss
variable: .skip 4
.section .text
.global main
main:
// Print Input statement
ldr x0,=input_number
bl printf
sub sp, sp, #16
// Recieve input
ldr x0,=input_spec
add x1, sp, #8
bl scanf
// Check if input is negative
ldr w0,[sp, #8]
cmp w0, #0
blt input_error
bl recurse
b exit
recurse:
sub sp, sp, #16
str w0,[sp, #4]
str x30,[sp, #12]
ldr x0,=print_num
bl printf
ldr w0,[sp, #4]
cmp w0, #0
beq zero_input
sub w0, w0, #1
bl recurse
ldr w0,[sp, #4]
ldr x0,=print_num
bl printf
zero_input:
ldr x30,[sp, #12]
add sp, sp, #16
ret
input_error:
ldr x0,=error
bl printf
b exit
exit:
// Exit syscall
mov x0,0
mov x8,93
svc 0
ret
 Here is the c++ code for the procedure. (This is simply

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!