Both parts please Consider the following high-level recursive procedure: long lo
ID: 3870618 • Letter: B
Question
Both parts please
Consider the following high-level recursive procedure: long long int flong long int n, long long int k long long int b b k+2; if (n=-O) b = 8; else b = b + 4 * n + f(n-1 ,k+1); return b + k; Translate the high-level procedure f into ARMv8 assembly language. · Pay particular attention to properly saving and restoring registers across procedure calls; Use the ARMv8 preserved register convention Clearly comment your code; . Assume that the procedure starts at address 0x00400100; . Keep local variable b in X19; Assume n and k are passed in XO and X1 respectively and that the result is returned in X2.Explanation / Answer
f(long long, long long):
push rbp
mov rbp, rsp
push rbx
sub rsp, 40
mov QWORD PTR [rbp-40], rdi
mov QWORD PTR [rbp-48], rsi
mov rax, QWORD PTR [rbp-48]
add rax, 2
mov QWORD PTR [rbp-24], rax
cmp QWORD PTR [rbp-40], 0
jne .L2
mov QWORD PTR [rbp-24], 8
jmp .L3
.L2:
mov rax, QWORD PTR [rbp-40]
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-24]
lea rbx, [rdx+rax]
mov rax, QWORD PTR [rbp-48]
lea rdx, [rax+1]
mov rax, QWORD PTR [rbp-40]
sub rax, 1
mov rsi, rdx
mov rdi, rax
call f(long long, long long)
add rax, rbx
mov QWORD PTR [rbp-24], rax
.L3:
mov rdx, QWORD PTR [rbp-24]
mov rax, QWORD PTR [rbp-48]
add rax, rdx
add rsp, 40
pop rbx
pop rbp
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.