x86 simple mov instruction

别来无恙 提交于 2019-12-08 12:04:16

问题


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 ecxth 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!