I'm am trying to understand machine code memory addressing for x86, and I've encountered two opposing general forms for addressing (using the ModRM and SIB bytes).
Most unofficial resources I consult suggest memory addressing is done in a subset of the general form [register1 + scale * register2 + displacement]
. An example would be [EAX+disp8]
for some 8 bit displacement. Example resources are:
https://cs.nyu.edu/courses/fall10/V22.0201-002/addressing_modes.pdf
http://wiki.osdev.org/X86-64_Instruction_Encoding#32.2F64-bit_addressing
But consulting the intel manual (Vol.2A, 2.1.5) it looks like the general form is instead [register1] + [scale * register2] + displacement
. For example, in the left column of Table 2-2, it shows [EAX]+disp8
. The notes at the bottom of the table suggest the same.
So which general form is correct? The first form yields an value in memory. The second form yields a memory address, but does so by first accessing other values in memory.
Keeping it mind that the []
operator is not distributive, that is [register1 + register2] !== [register1]+[register2]
, the two general forms are not identical. I imagine the first form is correct and I am not interpreting intel's manual correctly.