I am trying to figure out the behavior of conditional jumps (JE/JNE, JZ/JNZ) in the x86 instruction set familly.

Which condition flags CMP instruction sets and how, if the result is equal and if it is not? For example:

  • CMP eax, 0 (true)

  • CMP eax, 0 (false)


2 Answers 2


Furthermore, with the CMP instruction, the destination operand doesn't change. Just the flags.

Let me illustrate. Let's say EAX = 00000005 and EBX = 00000005. If we do this arithmetic operation:


What's happening, is in effect this:

EAX - EBX ----> 00000005 - 00000005

Since the result would be 0, but we don't change the destination operand in a CMP instruction, the zero flag is set to 1 (since it's true).

So, as we saw, depending on the result of the previous arithmetic operation, flags can be set accordingly:

enter image description here


The CMP instruction does internally a SUB and sets the flags accordingly.

So all flags that are set by a SUB are also set by CMP.

Namely the flags SF, ZF, AF, PF, and CF are set.

This information is taken from the Intel manual for the processors (https://software.intel.com/en-us/articles/intel-sdm).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.