please help with this problem I will rate asap!!! 2.) Convert the following code
ID: 3874812 • Letter: P
Question
please help with this problem I will rate asap!!!
2.) Convert the following code to ARM instructions. Assume a is in X0, b in X1, n in X2, and the result should go into X10. You may change the values in any of these registers. Implement the subroutine call by simply branching to the top of your code, but with the arguments updated appropriately. To end your program, call "BR X30" to return to the subroutine caller. Shorter and faster programs will be given more credit. int fib_iter (int a, int b, int n) f if (n== 0) return b; else return fib_iter (a+b, a, n-1)/Explanation / Answer
ARM code:
fib_iter(int, int, int):
push {fp, lr}
add fp, sp, #4
sub sp, sp, #16
str r0, [fp, #-8]
str r1, [fp, #-12]
str r2, [fp, #-16]
ldr r3, [fp, #-16]
cmp r3, #0
bne .L2
ldr r3, [fp, #-12]
b .L3
.L2:
ldr r2, [fp, #-8]
ldr r3, [fp, #-12]
add r0, r2, r3
ldr r3, [fp, #-16]
sub r3, r3, #1
mov r2, r3
ldr r1, [fp, #-8]
bl fib_iter(int, int, int)
mov r3, r0
.L3:
mov r0, r3
sub sp, fp, #4
pop {fp, lr}
bx lr
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.