Answered step by step
Verified Expert Solution
Link Copied!

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 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.
Here is my code so far, it works if you input any negative but the positive doesnt work or 0.
.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 w1,[sp, #8]
str w0,[sp, #4]
cmp w0, #0
beq zero_input
ldr x0,=print_num
bl printf
sub w0, w0, #1
bl recurse
ldr x0,=print_num
ldr w0,[sp, #4]
bl printf
ldr w1,[sp, #8]
add sp, sp, #16
ret
zero_input:
ldr x0,=print_num
bl printf
ldr w1,[sp, #8]
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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions