The code in c: 1 int swap_n_add(int *xp, int *yp) { 2 int x = *xp; 3 int y = *yp
ID: 3773901 • Letter: T
Question
The code in c:
1 int swap_n_add(int *xp, int *yp) {
2 int x = *xp;
3 int y = *yp;
4
5 *xp = y;
6 *yp = x;
7 return x + y;
8 }
The same code in assembly
Group the assembly code instructions with their corresponding statements in c
above to the best of your ability.
db-pedaS disas ump of assembler code for function swap-n-add: 0x080483ed : push %ebp 0x080483ee : mov xesp.xebp 0x080483f0 : sub $0x10,%esp 0x080483f3 (+6): mov 0x8(%ebp),%eax 0x080483f6 : mov (zeax mov [%eax),%eax 0x080483f8(+11> : mov %eax,-0x8(%ebp) 0x080483fb(+14) : mov 0xcC%ebp),%eax 0x080483fe(+17>: mov [%eax),%eax 0x08048400(+19>: mov %eax,-0x4(%ebp) 0x08048403(+22> : mov 0x6(%ebp),%eax m0 U 0x08048406(+25> : mov -0x4(%ebp),%eax m0U 0x08048409(+28>: mov %eax,(xeax) 0x0804840b(+30 > : mov 0xcC%ebp),%eax 0x0804840e(+33) : mov -0x8(%ebp),%eax 0x08048411(+36 > : mov %edx,(zeax) m0U > 0x08048413(+38>: mov -0x4(%ebp),%eax 0x08048416(+41> : mov -0x6(%ebp),%edx 0x08048419(+44) : add xedx,xeax 0x0804841b(+46): leave 0x0804841c: ret nd of assembler dump. >>>>>14792580368-467d r01369-11122233334444 0 0 0 1 1 1 1 1 1 44444 a 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 s p0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0Explanation / Answer
Matching the assembly code with C statements.
Push will put the value in stack and then it will move to register
So int swap_n_add(int *xp, int *yp) { = push %ebp
mov %esp, %esp
sub $0x10, %esp
Then int x = *xp; mov 0x8(%ebp),%eax
mov (%eax), %eax
mov %eax, -0x8(%ebp)
mov 0xc(%ebp), %eax
int y = *yp; (%eax), %eax
%eax,-0x4(%ebp)
0x8(%ebp), %eax
-0x4(%ebp), %edx
*xp = y; mov %edx, (%eax)
-0x(%ebp),%edx
%edx, (%eax)
*yp = x; mov %edx, (%eax)
-0x4(%ebp), %eax
-0x8(%ebp),%edx
return x + y; add %edx, %eax
leave
ret