I read Computer Systems: A Programmer's Perspective, Chapter 3 explains the mov instruction, and the explanation given in the book confuses me.
give function (p. 142 1 issue)
int exchange( int *xp, int y) { int x = *xp; *xp = y; return x; }
Function body assembly code
movl 8(%ebp), %eax //Get xp movl 12(%ebp), %edx //Get y movl (%eax), %ecx //Get x at *xp movl %edx, (%eax) //Store y at *xp movl %ecx, %eax //Set x as return value
What bothers me is what will be stored, and where Here's how I understand it:
movl 8(%ebp), %eax //Get xp
The CPU moves +8 bytes to the stack (from the frame pointer %ebp ), takes the value stored in this place, and stores this value in the %eax register (for allocation, it stores the value, not the address)
I'm right? Thanks!
assembly
newprint
source share