Question about intel assembly
I am trying to wo开发者_开发技巧rk my way through an Intel assembly file and I ran into a bit of code I don't understand.
# Save current stack pointer to old thread's stack, if any.
movl SWITCH_CUR(%esp), %eax
movl %esp, (%eax,%edx,1)
I understand that the first line moves the value of 12
offset from register %esp
into the register %eax
.
But I don't understand what the second line does it moves %esp
into what.
Is (%eax,%edx,1)
a logical and
operation? Or addition?
Any help would be great.
Thanks
The meaning is
mov %esp, (%eax + %edx * 1)
The number can be 1, 2, 4 or 8.
See http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax
(%eax,%edx,1)
refers to the location in memory whose address is formed by adding the value in %eax
to the value in %edx
. The 1 is the scale factor which doesn't actually "matter" because it is 1.
ADDENDUM
In detail (in case anyone else lands on this page):
mov %esp, %edx # move contents of esp into edx
Assuming edx contains 100 and eax contains 20:
mov %esp, (%edx) # move contents of esp in address 100
mov %esp, (%edx,%eax) # ... into address 100 + 20 = 120
mov %esp, (%edx,%eax,4) # ... into address 100 + (20*4) = 180
精彩评论