为什么`add cl, 2` 以 x86 十六进制打印 `80 c1 02`? [英] Why does `add cl, 2` print `80 c1 02` in x86 hex?

查看:19
本文介绍了为什么`add cl, 2` 以 x86 十六进制打印 `80 c1 02`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图缩小我的问题范围,以便我可以克服这个障碍.对我帮助不大.>

我正在运行 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 字段包含提供指令操作码扩展的数字.

我的问题是:

  1. 为什么汇编器决定在这里放置一个 ModR/M 字节?
  2. 什么是仅使用 r/m(寄存器或内存)操作数"?意思?什么操作数,它是说它识别出一个寄存器cl 和一个立即数2,所以它选择cl 因为它是一个寄存器?
  3. reg 字段包含提供指令操作码扩展的数字.";唔?这是什么意思?我只能从中收集到,/0 表示它是第 0 个寄存器?不过这行不通,似乎是错误的.
  4. 表 2-1 中有值 c1,它与有效地址"下的 cl 寄存器对齐.标题.虽然不知道是什么意思.相应的 R/M 位就在 001 处,它所在的列是 0.虽然这些对我来说还没有多大意义.

我如何说服自己这个 c1 字节是正确的?我如何从各种表格中读取所有符号,我如何仅通过查看组件和英特尔表格来自己推断?

解决方案

  1. 因为 80/0 ibOp/En 表示 MI 表示 Operand1 在 MODRM:r/米.
  2. 这意味着它只使用r/m"modr/m 的一部分,而不是reg"部分.
  3. 表示reg"部分包含一个常量 0 作为操作码扩展.
  4. 您查看 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:

/digit — A digit between 0 and 7 indicates that the ModR/M byte of the instruction uses only the r/m (register or memory) operand. The reg field contains the digit that provides an extension to the instruction's opcode.

My questions are:

  1. Why did the assembler decide to put a ModR/M byte here?
  2. 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 immediate 2, and so it chooses cl because it is a register?
  3. "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.
  4. Table 2-1 has the value c1 in it, which aligns with the cl register under the "Effective Address" header. Don't know what that means though. The corresponding R/M bit is right there at 001, and the column it's in is 0. 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?

解决方案

  1. Because the Op/En for the 80 /0 ib says MI which says that Operand1 is in MODRM:r/m.
  2. It means it's only using the "r/m" part of the modr/m and not the "reg" part.
  3. Means the "reg" part contains a constant 0 as an opcode extension.
  4. 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 the ECX/CX/CL/MM1/XMM1 row and voila, you got your C1 value.

这篇关于为什么`add cl, 2` 以 x86 十六进制打印 `80 c1 02`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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