Objective
Write an ARM program that takes two integers as input, x and y, and recursively calculates xy.
Requirements and Specifications
Your inputs x and y 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.
You may use X19-X27 only in your main function.
Recursion requires:
• Save the return address, arguments, and local variables in a new stack frame
• Recursively call procedure with BL
• Unwind the stack by restoring the return address, arguments, and local variables, and deallocating the stack frame
Your exponent function should have the following general form:
power(x, y):
if x is 0
return 0
else if y less than 0
return 0
else if y is 0
return 1
else
return x * power(x, y - 1)
Your arguments x and y should be passed to your power function in X0 and X1. Your return value should be placed in X2.
Again, you may use X19-X27 in your main function, but you may not use X19-X27 in your recursive function.
Some assumptions:
• x, y are 32-bit integers
• x0 = 1
• 00 = 0
• xy ≤ 230
IT MUST LOOK LIKE THIS.
SKELETON CODE MUST BE USED
.section .data
input_x_prompt : .asciz "Please enter x: "
input_y_prompt : .asciz "Please enter y: "
input_spec : .asciz "%d"
result : .asciz "x^y = %d\n"
.section .text
.global main
main:
# add code and other labels here
# branch to this label on program completion
exit:
mov x0, 0
mov x8, 93
svc 0
ret
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.