I'm just getting into x86 for a systems class and have a couple of questions:
1) Say I reference a piece of memory with:
(%eax)
The parentheses indicate I'm accessing memory and %eax
indicates I want to access that particular address in memory. So if register %eax
stores 0x104
, (%eax)
will return whatever is stored at memory location 0x104. Is this correct?
2) Say I want to swap the values stored at (%eax)
and (%ebx)
. Here's my attempt:
//store values in registers
movl (%eax) eax
movl (%ebx) ebx
//store values in opposite registers from where they came originally
movl ebx (%eax)
movl eax (%ebx)
Does this look right?
Thanks for the help, bclayman
That cannot be correct.
EAX
and EBX
start out containing memory locations. You then dereference the memory, moving the actual values into the registers of the same name:
MOVL (%EAX), EAX
MOVL (%EBX), EBX
EAX
and EBX
no longer contain memory addresses; they now contain the contents from those addresses. When you next do this:
MOVL EBX, (%EAX)
MOVL EAX, (%EBX)
you are storing the values from those memory locations into whatever memory location happens to be equal to those values which is almost certainly not what you want and almost guaranteed not to exchange the values.
The only way this would work if the memory locations were storing the value of the memory location in themselves, which wouldn't make a lot of sense.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments