I am trying to reconcile the differences between the main categories of addressing memory in x86, and want to see if I have the distinctions right. If I'm understanding things correctly, there are three broad ways, each with their own syntax.
The following examples will use the src
for the different address methods:
Literal/Immediate value.
For example, to move the decimal value
10
into%eax
:mov $10, %eax
Direct Register addressing.
Direct: For example, to move the value in
%ebx
into%eax
:mov %ebx, %eax
Indirect: This uses the format discussed in #3.
Offset/Indexed/Indirect addressing:
For example, relative to a register:
mov -4(%ebp), %eax
For example, relative to a label or address:
mov string(,%edi, 4), %eax
But, my main question here is that the three main categories cannot be used interchangeably.
For example, we cannot use an immediate value in offset
addressing, such as:
mov $2(%edi), %eax
Or, when doing direct register addressing, we cannot use an offset such as:
mov %eax(,%edi,2), %eax
Is that a correct understanding of the three main forms of memory addressing, or are there some things that I am missing here?