5

I have a piece of code which uses JNZ. When I assemble and link the binary, I see my JNZ is replaces with a JNE. I understand that both of them fundamentally are the same. But then why does NASM change it?

Also, is there any config option available to stop this change from happening while assembling?

nrz
  • 10,435
  • 4
  • 39
  • 71
ST-User
  • 395
  • 2
  • 3
  • 12

2 Answers2

11

I understand that both of them fundamentally are the same

JNE and JNZ have the same opcodes (0x75 for short jumps and 0x0f 0x85 for near jumps), so the assembler will create the same machine code for both of them.

When disassembling, the disassembler does not known anymore which one was used in the source and it has to take one of them.

Also, is there any config option available to stop this change from happening while assembling?

No, because it is not a real "replacement" - JNE and JNZ are simply different mnemonics for the same opcodes.

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
  • My next question is then why need them both? – ST-User Feb 11 '13 at 09:22
  • 4
    You can use them to make your code more readable and easier to understand - use `JNE` followed by a `CMP` instruction to make clear that you are checking for **equality**, and use `JNZ` if you simply want to check the zero flag (e.g. after a `SUB` instruction to check if the result is zero or not) – Andreas Fester Feb 11 '13 at 09:28
2

JNZ and JNE have exactly the same encoding (refer to Intel® 64 and IA-32 Architectures Software Developer’s Manual Vol. 2A 3-419). So whichever you use in the assembler, the disassembler would pick one and use the same notation throughout in the disassembled code.

JosephH
  • 8,465
  • 4
  • 34
  • 62