汇编 - 操作码与 nasm 指令

assembly - opcodes vs. nasm instructions

所以我最近尝试进入汇编,发现自己真的对 NASM 的工作方式感到困惑。据我所知,它是一种 'compiler' 用于将(助记符)指令转换为实际机器代码的汇编。现在我想知道 NASM 手册中列出的指令(www.nasm.us/doc/nasmdocb.html)和我的机器采用的操作码有什么区别?比如,假设我的 Intel 处理器有某种无人知晓且未在手册中列出的秘密操作码,NASM 仍然能够 assemble 它吗?还是只是 return 'invalid instruction'?并说我知道操作码的机器码格式,我可以手动插入吗?

NASM 支持 NASM 支持的内容。

可能确实有 "internal" 指令,或者在您的 NASM 版本构建后引入的指令,然后它就不知道了。

您可以使用 db 序列或类似的方式手动编码那些(或实际上 任何 指令)。

这个 old version of the nasm manual includes some instructions that Intel doesn't document, but that NASM supports. (That link is from the 标签 wiki。)

这些是 "secret opcodes" 人们 知道的。我假设人们已经测试了至少 3 或 4 个字节的每个可能序列,以找到像这样的未记录的操作码。当然,您不需要 NASM 知道如何对它们进行编码,因为您可以使用 db 到 assemble 目标文件中的任何字节。

这不是您实际问题的答案,但可能更符合您想知道的内容。就像 @500... 说的那样,NASM 只是一个从 table 已知助记符中查找字节序列的程序。它甚至不必在 x86 CPU 上 运行,并且没有接口来查询 CPU 指令的名称。

您可能想将您的问题编辑成一个有更有趣答案的问题。


例如:

SALC ; D6 [8086,UNDOC]

SALC is an early undocumented instruction similar in concept to SETcc (section A.150). Its function is to set AL to zero if the carry flag is clear, or to 0xFF if it is set.

它实际上在我的 Core2 CPU 上以 32 位模式运行。 (NASM 和 YASM 在组装 64 位代码时都拒绝它)。

如果不是很明显不要在可移植代码中使用它。它可能会在将来使用 D6 作为其他指令编码的第一个字节的 CPU 中被破坏。 Intel insn ref 手册附录 A 中操作码映射中的 D6 条目为空。

All blanks in opcode maps are reserved and must not be used. Do not depend on the operation of undefined or blank opcodes.


current version of the NASM manual 不列出描述,但仍列出所有助记符,包括标记为 UNDOC 的助记符。据推测,该附录因 SSE 指令而变得过于臃肿。