I'm writing a compiler for x86/x64 CPU instructions and I can't seem to figure out what people mean by 'displacement' address. For example the Add instruction is detailed here: http://www.c-jump.com/CIS77/CPU/x86/X77_0150_encoding_add_edx_displacement.htm
I'm just trying to implement the add instruction where a register is added to a normal memory address. The problem is, the address is a 'displacement address'. Does that mean the address is a signed value that's the offset from the instruction location?
There are a few different forms of indirect operands in x86:
The "displacement" is just a constant that gets added to the rest of the address. In cases where there is no component of the address other than the constant, it is still called a "displacement". This is mainly for consistency with the other addressing forms.
Another way to look at it is that all addresses are of the form
[reg * constant + reg + displacement]
With each of the components allowing a value of 0.
The [displacement] form is just the encoding where all components other than the displacement are zero.
As a compiler writer the last 2 forms are particularly interesting. They make it easy to encode things like pArray[index]->field + 1
in a single instruction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With