**** I need the answer to questions #7. Translate the following code to x86. Ass
ID: 3788974 • Letter: #
Question
**** I need the answer to questions #7.
Translate the following code to x86. Assume standard conventions for passing parameters and return values using registers. int minusTwo (int n) {n = n - 2; return n;} Translate the following code to x86. Assume standard conventions for passing parameters and return values using registers. Use %rcx for n, and %rbx for m. n = 12; m = minusTwo (n); n = n + m; Assume your previous code from questions 5 and 6 both use the same register, %rbx, to hold different values. Write code for minus Two that demonstrates proper "filling" and "spilling" of %rbx to the stack.Explanation / Answer
5)
minusTwo(int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
sub DWORD PTR [rbp-4], 2
mov eax, DWORD PTR [rbp-4]
pop rbp
ret
6)
minusTwo(int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
sub DWORD PTR [rbp-4], 2
mov eax, DWORD PTR [rbp-4]
pop rbp
ret
sampleMath():
push rcx
mov rcx, rsp
sub rsp, 16
mov DWORD PTR [rcx-4], 12
mov eax, DWORD PTR [rcx-4]
mov edi, eax
call minusTwo(int)
mov DWORD PTR [rbx-8], eax
mov eax, DWORD PTR [rbx-8]
add DWORD PRT [rcx-4], eax
nop
leave
ret
7)
minusTwo(int):
push rbx
mov rbx, rsp
mov DWORD PTR [rbx-4], edi
sub DWORD PTR [rbx-4], 2
mov eax, DWORD PTR [rbx-4]
pop rbx
ret
sampleMath():
push rbx
mov rbx, rsp
sub rsp, 16
mov DWORD PTR [rbx-4], 12
mov eax, DWORD PTR [rbx-4]
mov edi, eax
call minusTwo(int)
mov DWORD PTR [rbx-8], eax
mov eax, DWORD PTR [rbx-8]
add DWORD PRT [rbx-4], eax
nop
leave
ret
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.