问题
This is a simple question but I can't find reliable answers on google.
What does this instruction mean:
movl %eax, (%esi, %ecx, 4)
Is it move the value at register eax
to the value in memory that (%esi, %ecx, 4)
is pointing too?
(%esi, %ecx, 4)
is for an array. So it means Array[Xs + 4i] where Xs is the starting point in memory for the Array and i is just an offset in the integer array.
回答1:
Exactly correct. This is AT&T syntax, so the source comes first, then the destination. Thus, it stores the contents of the eax
register to the memory location esi + 4*ecx
.
If you like to think of this as an array, it stores eax
to the ecx
th entry of an array of 4-byte objects based at esi
.
回答2:
Yes, that's exactly what it is. In AT&T syntax, memory addressing is written as:
offset(base, index, multiplier)
offset
is a signed constant specifying the offset from base
, base
is a register of where to start at, index
is the register specifying how far after the start of the array to look, after multiplying by multiplier
, which can be 1, 2, 4, or 8.
You must specify at least one of offset
, base
, and index
. To use index
without base
, you need to precede it with a comma ( (, index)
). If you don't specify multiplier
, it defaults to 1.
In Intel syntax, this is written as:
[base + index*multiplier + offset]
This is easier to understand, since it is simply a math problem.
来源:https://stackoverflow.com/questions/7518448/x86-simple-mov-instruction