Author Topic: How does nasm cope with those additions to the basic x86-64 instruction set?  (Read 8943 times)

Offline KGM

  • Jr. Member
  • *
  • Posts: 2
As you know, most CPUs implement the x86-64 instruction set.
NASM is more or less build to allow programmers to easily write more or less x86-64 code...
I don't doubt that it does this properly...

However, due to the x86-64 standard being pretty old, many chip producers designed their chips in a way so that they could do more...
By adding new instructions...

Some of these "additions", I see, are part of NASMs repertoire...

That leads to a few questions:

What are these NASM instructions compiled to? Are they compiled to the corresponding x86-64 additive instructions, or are they rather emulated using normal x86-64 instructions?

What happens if I run a NASM program containing such instructions on a CPU that does not support them? will the program crash? Or does NASM make the programs in a way such that they, for example, check the CPU kind on startup and adapt?

Does NASM cover all important additions made to the x86-64 instruction set over the past decades?

Offline ig

  • Jr. Member
  • *
  • Posts: 12
NASM is an assembler, not a compiler of a high-level language. So it just "translates" the instructions specified in the .asm source into the corresponding opcodes.
There's no CPUID checking or emulation - that's up to you, as the author of the .asm source.
So yes, if you use a new instruction and run the compiled executable on a CPU that doesn't support it (and the execution actually reaches that instruction), the program will crash.

Yes, NASM supports recent additions. I'm not aware of any missing x86 instructions for existing CPUs. (Well, except for a few of those that are not actually documented anywhere, such as some of the Via/Zhaoxin instructions).

Offline KGM

  • Jr. Member
  • *
  • Posts: 2
So NASM basically gives you the ability to write code for modern CPUs  8).
But you have to do the feature bit checking yourself  ::).
Thank you for your very clear (and pleasant) answer!

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Right. Do see the "CPU" directive...

https://www.nasm.us/docs/2.14rc0/nasmdoc6.html#section-6.8

... but it may not help you... It does not  alter code, but will throw an error of you use an instruction not available at the specified level. I don't know how up-to-date it is...

Best,
Frank