문제

I'm new to x86.

I know what this kind of thing with the pointers means.

*command* %eax, %ebx

But how are these different, and what do they mean?

*command* %eax, (%ebx)
*command* (%eax), %ebx
*command* (%eax, %ebx, 4), %ecx
도움이 되었습니까?

해결책

I think your question is, "what does the parentheses around a register's name mean/do?" At a high level, the parentheses say to perform a load from a memory address in and use that value in the instruction. Ie, whereas

*command* %eax, %ebx

operates on the values in the %eax and %ebx registers directly,

*command* (%eax), (%ebx)

loads the values from memory pointed to by %eax and %ebx and operates on them. There are actually a few more variants of the parentheses than you listed. For a description of them (including the last instruction example that you asked about), check here.

Hope that helps. Feel free to post back if you have any more questions.

다른 팁

Assume the following operations:

movl %eax, (%ebx)               [1]
movl (%eax), %ebx               [2]
movl (%eax, %ebx, 4), %ecx      [3]

1, The first one will copy the value of eax into an address stored in ebx, smiler to this in C:

*(int *)ebx = eax;    // copy eax into address

2, The second will copy the value stored in an address at eax into ebx:

ebx = *(int *)eax;    // copy what in address into ebx

3, This is an array operation, where ebx is the index and 4 is the size of an element of the array.

ecx = ((int *) p)[ebx];

calculated as:

ecx = *(int *)((char *)p + ebx * sizeof(int));

In AT&T asm syntax, parenthesis mean "dereference" -- roughly the same as the unary * operator in C. So some rough equivalences:

movl  %eax, %ebx            eax = ebx
movl  %eax, (%ebx)          eax = *ebx
movl  (%eax), %ebx          *eax = ebx

That leqaves your last example:

movl  (%eax, %ebx, 4), %ecx

In this case, there are multiple values that are combined to form the address to dereference. It's roughly equivalent to

*(eax + ebx*4) = ecx
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top