Please give explanation as well Consider the following assembly code: mov 0x8(%e
ID: 3810820 • Letter: P
Question
Please give explanation as well
Consider the following assembly code: mov 0x8(%ebp), %eax mov (%eax), %edx mov 0xc (%ebp), %eax mov (%eax), %eax add %eax, %edx mov 0x8 (%ebp), %eax mov %edx, (%eax) mov %edx, (%eax) If 0xB (%ebp) and Oxc (%ebp) refer to the function arguments a and b respectively, which one of the following choices represent the C equivalent of the assembly code above? void func(int* a, int* b) {*a = *a + *b; return;} void func(int* a, int* b) {*b = *a + *b; return;} void func(int* a, int* b) {b = a + b; return;} void func(int* a, int* b) {a = b + a; return;} void func(int* a, int* b) {int tmp = *b *b = *a; *a = tmp; return;}Explanation / Answer
First statement moves the memory address of argument a to register eax.
Second statement moves the content at memory address in register eax to edx.
Third statement moves the memory address of argument b to register eax.
Fourth statement moves the content at memory address in register eax to eax.
Fifth statement add the contents of register eax and edx and then store the result in register edx.
Sixth statement moves the memory address of argument a to register eax.
Seventh statement moves the content of register edx to the memory address at register eax.
So the option 1 is the answer because the final statement stores the result of addition of a and b to the memory address stored in a.