Write a Y86 program to run and test the following C code int

Write a Y86 program to run and test the following C code: int f(int x) {return 16*x;} int g(int a, int b) {return f(a) + f(b);}

Solution

Answer:

f(int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
mov eax, DWORD PTR [rbp-4]
sal eax, 4
pop rbp
ret
g(int, int):
push rbp
mov rbp, rsp
push rbx
sub rsp, 8
mov DWORD PTR [rbp-12], edi
mov DWORD PTR [rbp-16], esi
mov eax, DWORD PTR [rbp-12]
mov edi, eax
call f(int)
mov ebx, eax
mov eax, DWORD PTR [rbp-16]
mov edi, eax
call f(int)
add eax, ebx
add rsp, 8
pop rbx
pop rbp
ret

 Write a Y86 program to run and test the following C code: int f(int x) {return 16*x;} int g(int a, int b) {return f(a) + f(b);}SolutionAnswer: f(int): push rbp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site