Is there anyway to specify what processor we are targeting with the code assembled using NASM ?
For example, lets say I want to target only 8086, and hence using this instruction should be invalid:
mov eax, cr0
since eax
/cr0
are not there in 8086.
Or is it that NASM works for the "x86 family", and then it is on the programmer to make sure the code is written for the correct processor and is run on the ones where the instructions used are supported ?
Also, what if an instruction is supported in one processor but not in other .I guess as long as we talk about the same processor family this wouldn't happen, but what if such a situation does come up at some point ? Does NASM have functionality to support that ?
I have done some searching about all this, but couldn't find anything that answers this directly. Sorry if these questions sound stupid/rudimentary.
You can use the CPU
directive. From the fine manual:
The CPU directive restricts assembly to those instructions which are available on the specified CPU. […]
Current CPU keywords are:
CPU 8086
– Assemble only 8086 instruction setCPU 186
– Assemble instructions up to the 80186 instruction setCPU 286
– Assemble instructions up to the 286 instruction setCPU 386
– Assemble instructions up to the 386 instruction setCPU 486
– 486 instruction setCPU 586
– Pentium instruction setCPU PENTIUM
– Same as 586CPU 686
– P6 instruction setCPU PPRO
– Same as 686CPU P2
– Same as 686CPU P3
– Pentium III (Katmai) instruction setsCPU KATMAI
– Same as P3CPU P4
– Pentium 4 (Willamette) instruction setCPU WILLAMETTE
– Same as P4CPU PRESCOTT
– Prescott instruction setCPU X64
– x86-64 (x64/AMD64/Intel 64) instruction setCPU IA64
– IA64 CPU (in x86 mode) instruction set- […]