I need the answer to questions 7 Translate the following co

**** 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.

Solution

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

**** I need the answer to questions #7. Translate the following code to x86. Assume standard conventions for passing parameters and return values using register
**** I need the answer to questions #7. Translate the following code to x86. Assume standard conventions for passing parameters and return values using register

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site