Assembly 编码ADC EAX、ECX-2种不同的编码方式?(arch x86)

Assembly 编码ADC EAX、ECX-2种不同的编码方式?(arch x86),assembly,x86,Assembly,X86,我正在浏览一本英特尔指令集手册,它看起来有两种不同形式的ADC可以匹配/编码ADC EAX,ECX,如下所示: ADC r/m32, r32 (11 /r , which encodes to 11C8) 或 我的问题是(假设我计算正确),11C8和13C1是否相等?汇编程序在选择一个编码时会考虑哪些因素?这个问题是从实现汇编程序的角度出发的,所以这个问题是一般性的,而不是关于这个特定的假设指令 如果这是一个冗长的答案,请为我指出一个正确的方向,因为我在谷歌上搜索它的尝试失败了。这是指令编码

我正在浏览一本英特尔指令集手册,它看起来有两种不同形式的
ADC
可以匹配/编码
ADC EAX,ECX
,如下所示:

ADC r/m32, r32  (11 /r , which encodes to 11C8)

我的问题是(假设我计算正确),11C8和13C1是否相等?汇编程序在选择一个编码时会考虑哪些因素?这个问题是从实现汇编程序的角度出发的,所以这个问题是一般性的,而不是关于这个特定的假设指令

如果这是一个冗长的答案,请为我指出一个正确的方向,因为我在谷歌上搜索它的尝试失败了。

这是指令编码。任何在指令中使用多个参数的体系结构都具有这一点

想想一个RISC架构,它有
添加rx,ry,rz
,将ry和rz的总和分配到rx中,然后你可以对
添加rx,ry,rz
添加rx,rz,ry
进行编码,它们都是等价的

在x86中,每个指令(通常)只有2个参数,但您可以选择它们之间的方向,因为您可以存储到内存或从内存读取。如果不使用内存,则可以在两个寄存器之间选择方向,因此有两种编码方式

您可以使用它来识别一些编译器/汇编器。对于某些汇编程序,您可以选择使用哪种编码。在GAS中,您可以使用它来强制它发出交替编码

10 de   adcb   %bl,%dh
12 f3   adcb.s %bl,%dh

ADC的二进制编码为(assumming reg reg操作):

当指令与ADC EAX、ECX等两个寄存器一起使用时,有两种可能的编码:

a) EAX= EAX + ECX, COP= 13h, the "normal" case
00010011 11|000|001 where d=1 meaning 000 (EAX) is the destination register and 001 (ECX) is the other register.

b) EAX= ECX + EAX, COP= 11h, 
00010001 11|001|000 d=0 meaning 001 (ECX) is not the destination register so 000(EAX) must be the destination register.

几乎有两条操作数指令涉及reg reg或reg mem操作数。D位涉及reg reg或reg mem操作数。

是的,它们是等效的。一些表格参考,有时在使用Google GAS时,您必须使用一些小技巧/s,这有了编码覆盖的新语法,例如使用r/m源进行编码的
{load}
前缀。或者使用
{disp32}
前缀强制更长的寻址模式。
000100dw  Mod Reg Ind 
d= destination, 1 if Reg is the destination register, 0 if not
w= word operation, =0 if byte operation, =1 32 bit operation
Reg= is the register to use as a destination Register
Mod / Ind fields are used to specify the other Register involved, Mod=11, Ind= the other register
a) EAX= EAX + ECX, COP= 13h, the "normal" case
00010011 11|000|001 where d=1 meaning 000 (EAX) is the destination register and 001 (ECX) is the other register.

b) EAX= ECX + EAX, COP= 11h, 
00010001 11|001|000 d=0 meaning 001 (ECX) is not the destination register so 000(EAX) must be the destination register.