Consider the following C code void fint x int y x y y 0

Consider the following C code: void f(int *x, int *y) { *x = *y; *y = 0; } Convert the above code to x86 (end with a ret instruction). Obey the x86 register conventions, including the use of %ebp and %esp:

Solution

Solution:

EBP is generally used to access data on stack,when this register is used to specify an address,segment register is used implicitly.

ESP is stack pointer and relstive to segment register.

.globl f

f:

pushq   %ebp
movq   %esp, %ebp
movq   %edi, -8(%ebp)
movq   %esi, -16(%ebp)
movq   -16(%ebp), %eax
movl   (%eax), %edx
       movq   -8(%ebp), %eax
movl   %edx, (%eax)
       movq   -16(%ebp), %eax
movl   $0, (%eax)
  nop /no operation
popq   %ebp
ret      

 Consider the following C code: void f(int *x, int *y) { *x = *y; *y = 0; } Convert the above code to x86 (end with a ret instruction). Obey the x86 register co

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site