assemblyx86reverse-engineeringollydbgcmp

JNZ & CMP Assembly Instructions


Correct me if I am wrong.

This is my understanding of JNZ and CMP.

JNZ - The jump WILL take place if the Z Flag is NOT zero (1)

CMP - If the two values are equal, the Z Flag is set (1) otherwise it is not set (0)

Olly DBG

This is a flash tutorial I am watching. It is teaching the solution to a simple CrackMe.

As you can see, the previous instruction compared AL with 47h. They were equal which set the Z flag. (You can see it in the Registers windows on the right side)

The next instruction is a JNZ. My understanding was that the jump will take place if the Z flag is set. The Z flag IS set, but the jump doesn't take place!

Why?


Solution

  • JNZ is short for "Jump if not zero (ZF = 0)", and NOT "Jump if the ZF is set".

    If it's any easier to remember, consider that JNZ and JNE (jump if not equal) are equivalent. Therefore, when you're doing cmp al, 47 and the content of AL is equal to 47, the ZF is set, ergo the jump (if Not Equal - JNE) should not be taken.