Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NASM changes JNZ to JNE while assembling? Why?

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?

like image 574
ST-User Avatar asked Feb 11 '13 06:02

ST-User


2 Answers

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.

like image 177
Andreas Fester Avatar answered Oct 10 '22 17:10

Andreas Fester


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.

like image 27
JosephH Avatar answered Oct 10 '22 17:10

JosephH