assembly - NASM 是否有默认目标处理器?

标签 assembly nasm processor

是否可以指定我们使用 NASM 组装的代码所针对的处理器?

例如,假设我只想定位 8086,因此使用此指令应该无效:

mov eax, cr0

因为 eax/cr0 在 8086 中不存在。

或者 NASM 是否适用于“x86 系列”,然后程序员需要确保代码是为正确的处理器编写的,并且在支持所使用的指令的处理器上运行?

此外,如果一个指令在一个处理器中受支持,但在其他处理器中不支持怎么办。我想只要我们谈论相同的处理器系列,这种情况就不会发生,但如果这种情况在某个时候确实出现怎么办? NASM 是否有支持该功能的功能?

我已经对所有这些进行了一些搜索,但找不到任何可以直接回答这个问题的内容。抱歉,如果这些问题听起来很愚蠢/初级。

最佳答案

您可以使用CPU指令。来自 fine manual :

The CPU directive restricts assembly to those instructions which are
available on the specified CPU.

Options are:

CPU 8086 Assemble only 8086 instruction set
CPU 186 Assemble instructions up to the 80186 instruction set
CPU 286 Assemble instructions up to the 286 instruction set
CPU 386 Assemble instructions up to the 386 instruction set
CPU 486 486 instruction set
CPU 586 Pentium instruction set
CPU PENTIUM Same as 586
CPU 686 P6 instruction set
CPU PPRO Same as 686
CPU P2 Same as 686
CPU P3 Pentium III (Katmai) instruction sets
CPU KATMAI Same as P3
CPU P4 Pentium 4 (Willamette) instruction set
CPU WILLAMETTE Same as P4
CPU PRESCOTT Prescott instruction set
CPU X64 x86-64 (x64/AMD64/Intel 64) instruction set
CPU IA64 IA64 CPU (in x86 mode) instruction set

关于assembly - NASM 是否有默认目标处理器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21580667/

相关文章:

c++ - 为什么 x86/x86_64 上的顺序语义通过 MOV [addr], reg + MFENCE 而不是 + SFENCE 使用?

c - 8 个 6 位单元的 48 位字符串 : how to get middle 4 bits of each unit quickly

汇编无限循环(jmp -2)

optimization - 如果处理器支持乱序执行,那么优化数据危害是否有意义?

gcc - 我的处理器的汇编指令集

java - 如何在带注释的类上生成方法?

assembly - 使用 LIB-USB 传输随机字节数时如何修复 "Error -5"?

c - gcc 是否支持嵌入式汇编语法?

linux - 如何在 Linux 上使用系统调用等待击键中断?

assembly - 对 10 个数字求和并在 NASM 中打印结果