x86/x64 添加位移寻址 [英] x86/x64 Add Displacement addressing
问题描述
我正在为 x86/x64 CPU 指令编写编译器,但我似乎无法弄清楚人们所说的位移"地址是什么意思.例如,这里详细介绍了添加指令:http://www.c-jump.com/CIS77/CPU/x86/X77_0150_encoding_add_edx_displacement.htm
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?
推荐答案
在 x86 中有几种不同形式的间接操作数:
There are a few different forms of indirect operands in x86:
- [注册]
- [reg + 位移]
- [位移]
- [reg * 常量 + reg]
- [reg * 常数 + reg + 位移]
位移"只是一个常量,它被添加到地址的其余部分.如果除了常量之外没有地址的组成部分,它仍然被称为位移".这主要是为了与其他寻址形式保持一致.
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 * 常数 + reg + 位移]
[reg * constant + reg + displacement]
每个组件都允许值为 0.
With each of the components allowing a value of 0.
[displacement] 形式只是一种编码,其中除位移之外的所有分量都为零.
The [displacement] form is just the encoding where all components other than the displacement are zero.
作为编译器编写者,最后两种形式特别有趣.它们使在单个指令中对 pArray[index]->field + 1
之类的内容进行编码变得容易.
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.
这篇关于x86/x64 添加位移寻址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!