I am reading my tutorial and it has code for the swap function:
In C:
int exchange(int *xp, int y) { int x = *xp; *xp = y; return x; }
In x86 build with annotations:
// xp is at %ebp + 8, y at %ebp + 12 movl 8(%ebp), %edx // get xp movl (%edx), %eax // get x at xp movl 12(%ebp), %ecx // get y movl %ecx, (%edx) // store y at xp
So, from my understanding, if int * xp pointed to int I am at address A, then the first line of assembly code stores A in% edx. Then it becomes dereferenced in the second row and stored in% eax.
If this is true, I wonder why line 1 "8 (% ebp)" does not play the pointer, storing int I in% edx instead of address A? Isn't that what parentheses do in an assembly?
Or does this mean that when pointers are pushed onto the stack, the address of the pointer is pushed, not the value it has, so that 8 (% ebp) technically contains & xp?
I just wanted to clarify if I understood correctly.
c assembly pointers x86 att
Chang liu
source share