【问题标题】:Encoding ADC EAX, ECX - 2 different ways to encode? (arch x86)编码 ADC EAX、ECX - 2 种不同的编码方式? (拱 x86)
【发布时间】:2014-03-06 07:03:37
【问题描述】:

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

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

ADC r32, r/m32  (13 /r, which encodes to 13C1)

我的问题是(假设我计算正确),11C813C1 是否等效?汇编程序在选择一种编码而不是另一种编码时会考虑哪些因素?问题是从实现汇编器的角度来看的,所以问题是笼统的,而不是关于这个特定的假设指令。

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

【问题讨论】:

  • 是的,它们是等价的。

标签: assembly x86


【解决方案1】:

这是指令编码的redundancy。任何在指令中使用多个参数的架构都有这个。

考虑一个具有add rx, ry, rz 的 RISC 架构,它将 ry 和 rz 的总和分配给 rx,然后您可以编码 add rx, ry, rzadd rx, rz, ry,它们都是等价的。

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

您可以使用它来识别一些编译器/汇编器。对于某些汇编器,您可以选择要使用的编码。在 GAS 中,您可以使用 .s suffix 强制它发出备用编码

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

【讨论】:

【解决方案2】:

ADC 的二进制编码是(假设 reg-reg 操作):

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

当指令与 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.

D 位几乎涉及两个操作数指令,涉及 reg-reg 或 reg-mem 操作数。

【讨论】:

    猜你喜欢
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多