什么是“X"?r8-15 寄存器编码的一部分? [英] What is the "X" part of the encoding of the r8-15 registers?

查看:25
本文介绍了什么是“X"?r8-15 寄存器编码的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的 X 值是什么?在拆解时有以下两条说明:

加 $1, %dl加 1 美元,%r10b

我明白了:

<预><代码>>>>x/3bt $pc0x401000 <_start>: 10000000 11000010 00000001>>>x/4bt $pc+30x401003 <_start+3>: 01000001 10000000 11000010 00000001

所以,我猜 X 是前缀字节中的 LSB,因为 0100 是静态的,对吗?X 是什么意思,每当使用 r8-r15 寄存器之一时,这意味着什么,需要添加/前缀一个额外的字节,以便说明这是寄存器 r10 而不是 rdx".?

解决方案

X 是您在页面顶部链接的表格中的占位符.它适用于任何机器代码中的注册号.前导位来自 REX 前缀中的字段之一,具体取决于这是哪个字段.

这就是为什么 0.010 位模式中的前导位与其他 3 位分开的原因;没有 REX 前缀,它是隐式 0.

在您的情况下,它是 .B 位,因为它正在修改 add $imm8, r/m8r/m 字段>.(因为我们可以看到它是 REX 前缀的低位).

REX 前缀(您链接的同一页面上的另一部分)是如何x86-64 通过前缀添加了 8 个新寄存器,并可选择 32 位或 64 位操作数大小,而无需修改其余指令编码.16 位和 32 位 x86 机器代码当然使用 3 位字段作为寄存器编号.

REX 前缀可以为 add r8, [rcx + r9*8] 等指令提供第 4 个 reg-num 位,其中包括 3 个寄存器编号(MODRM.reg、MODRM.rm 或 SIB.基和 SIB.index).并为 64 位操作数大小设置了 .W 位.

选择 X 作为占位符有点令人困惑,因为其中一个 REX 字段被命名为 X(SIB.索引).但这不是他们所指的.


另请注意,r10lr10b 是同一个寄存器的替代名称.AMD 最初在定义 AMD64 时使用 r8-15b(字节").英特尔显然后来发明了 r8-15l(低")名称(为了与 AL/CL/DL/BL/SPL/... 相似),但是 b 名称更受欢迎和广泛.为什么 Apple 使用 R8l 作为字节寄存器而不是 R8b?

On this chart it shows that both registers have the 0b010 for the register value:

What is the X value here? In dissassembling the following two instructions:

add $1, %dl
add $1, %r10b

I get:

>>> x/3bt $pc
0x401000 <_start>:                  10000000    11000010    00000001
>>> x/4bt $pc+3
0x401003 <_start+3>:    01000001    10000000    11000010    00000001

So, I'm guessing the X is the LSB in the prefix byte since the 0100 is static, correct? What does the X mean and what does that mean whenever one of the r8-r15 registers is used an extra byte needs to be added/prefixed in order to say that "This is register r10 not rdx" ?

解决方案

X is a placeholder in that table you linked at the top of the page. It applies any time there's a register number in machine code. The leading bit comes from one of the fields in the REX prefix, depending on which which field this is.

That's why the leading bit is separated from the other 3 in the 0.010 bit pattern; with no REX prefix it's implicitly 0.

In your case, it's the .B bit because it's modifying the r/m field of ModRM in add $imm8, r/m8. (And because we can can see it's the low bit of the REX prefix).

The REX prefix (another section on the same page you linked) is how x86-64 added 8 new registers, and a choice of 32 or 64-bit operand-size, via a prefix without modifying the rest of the instruction encoding. 16 and 32-bit x86 machine code of course uses 3-bit fields for register numbers.

The REX prefix can provide a 4th reg-num bit for instructions like add r8, [rcx + r9*8] which includes 3 register numbers (MODRM.reg, MODRM.rm or SIB.base, and SIB.index). And has the .W bit set for 64-bit operand size.

The choice of X as a placeholder is slightly confusing because one of the REX fields is named X (the SIB.index). But that's not what they're referring to.


Also note that r10l and r10b are alternate names for the same register. AMD originally used r8-15b ("byte") when defining AMD64. Intel apparently invented the r8-15l ("low") names later (for similarity with AL/CL/DL/BL/SPL/...), but the b names are more popular and widespread. Why does Apple use R8l for the byte registers instead of R8b?

这篇关于什么是“X"?r8-15 寄存器编码的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆