问题描述
试图缩小我的问题范围,以便我可以克服这个障碍.这对我帮助不大.>
我正在运行 NASM 以查看以十六进制表示的程序集输出.
测试:@nasm -f macho64 test.asm@objdump -x86-asm-syntax=intel --full-leading-addr -d test.o.PHONY:测试
里面有一些东西,其中之一是:
添加 cl, 2
输出为:
80 c1 02
查看 英特尔手册,我转到 ADD 部分,在那里显示:
80/0 ib
看起来足够接近了,80
在那里,ib
是我的数字 2
立即数.但是如何从 /0
计算这个 c1
呢?
文档说:
/digit — 0 到 7 之间的数字表示指令的 ModR/M 字节仅使用 r/m(寄存器或内存)操作数.reg 字段包含提供指令操作码扩展的数字.
我的问题是:
- 为什么汇编器决定在这里放置一个 ModR/M 字节?
- 什么是仅使用 r/m(寄存器或内存)操作数"?意思?什么操作数,它是说它识别出一个寄存器
cl
和一个立即数2
,所以它选择cl
因为它是一个寄存器? - reg 字段包含提供指令操作码扩展的数字.";唔?这是什么意思?我只能从中收集到,
/0
表示它是第 0 个寄存器?不过这行不通,似乎是错误的. - 表 2-1 中有值
c1
,它与有效地址"下的cl
寄存器对齐.标题.虽然不知道是什么意思.相应的 R/M 位就在001
处,它所在的列是0
.虽然这些对我来说还没有多大意义.
我如何说服自己这个 c1
字节是正确的?我如何从各种表格中读取所有符号,我如何仅通过查看组件和英特尔表格来自己推断?
- 因为
80/0 ib
的Op/En
表示MI
表示 Operand1 在MODRM:r/米
. - 这意味着它只使用r/m"modr/m 的一部分,而不是reg"部分.
- 表示reg"部分包含一个常量
0
作为操作码扩展. - 您查看 modr/m 表 2-2,它有一个标题行,上面写着/digit (Opcode)".因此,您选择
0
列是因为/0
.然后选择ECX/CX/CL/MM1/XMM1
行,瞧,你得到了C1
值.
Trying to narrow my question down so I can get past this hurdle. This isn't helping me much.
I am running NASM to see what the output of assembly is in terms of hex.
test:
@nasm -f macho64 test.asm
@objdump -x86-asm-syntax=intel --full-leading-addr -d test.o
.PHONY: test
In there I have some stuff, one of which is this:
add cl, 2
It outputs as:
80 c1 02
Looking at the Intel Manuals, I go to the ADD section, where it shows this:
80 /0 ib
That looks close enough, the 80
is there, and the ib
is my number 2
immediate value. But how to calculate this c1
from the /0
?
The docs say:
My questions are:
- Why did the assembler decide to put a ModR/M byte here?
- What does "uses only the r/m (register or memory) operand" mean? What operand, is it saying it recognizes there is a register
cl
and an immediate2
, and so it choosescl
because it is a register? - "The reg field contains the digit that provides an extension to the instruction's opcode." Hmm? What does this mean? All that I can about gather from this is,
/0
means it's the 0th register? That doesn't work out though, seems wrong. - Table 2-1 has the value
c1
in it, which aligns with thecl
register under the "Effective Address" header. Don't know what that means though. The corresponding R/M bit is right there at001
, and the column it's in is0
. Though none of that means much to me yet.
How do I convince myself that this c1
byte is correct? How do I read all the signs from the various tables, how could I deduce it myself from just looking at the assembly and the Intel tables?
- Because the
Op/En
for the80 /0 ib
saysMI
which says that Operand1 is inMODRM:r/m
. - It means it's only using the "r/m" part of the modr/m and not the "reg" part.
- Means the "reg" part contains a constant
0
as an opcode extension. - You look at the modr/m table 2-2, it has a heading row that says "/digit (Opcode)". So you pick the
0
column because of the/0
. Then pick theECX/CX/CL/MM1/XMM1
row and voila, you got yourC1
value.
这篇关于为什么`add cl, 2` 以 x86 十六进制打印 `80 c1 02`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!