I am reading "Computer Systems: A Programmer Perspective", chapter 3 explains mov instruction, and explanation give in a book confuses me.
give a function (page 142 1's edition)
int exchange( int *xp, int y)
{
int x = *xp;
*xp = y;
return x;
}
Assembly code of function's body
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 confuses me, is what is going to be stored, and where
Here is how I understand this:
movl 8(%ebp), %eax //Get xp
CPU moves +8 bytes up the stack(from frame pointer %ebp), takes the value stored at that location, and stores this value at the register %eax(to emphasis - stores the value, not the address)
I am right ? Thanks !
Yeah, it sounds like you've got it right. IMHO, the AT&T 8(%ebp) syntax is less intuitive than the Intel [ebp+8] which is more clear. The brackets show that you're using the value at the address in the register, and the number is the offset from that address you actually want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With