Difference between JE/JNE and JZ/JNZ

JE and JZ are just different names for exactly the same thing: a
conditional jump when ZF (the “zero” flag) is equal to 1.

(Similarly, JNE and JNZ are just different names for a conditional jump
when ZF is equal to 0.)

You could use them interchangeably, but you should use them depending on
what you are doing:

  • JZ/JNZ are more appropriate when you are explicitly testing
    for something being equal to zero:

    dec  ecx
    jz   counter_is_now_zero
  • JE and JNE are more appropriate after a CMP instruction:

    cmp  edx, 42
    je   the_answer_is_42

    (A CMP instruction performs a subtraction, and throws the value of the result away, while keeping the flags; which is why you get ZF=1 when the operands are equal
    and ZF=0 when they’re not.)

Leave a Comment