Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 901
43.52.4D. Avatar asked Feb 12 '13 20:02

43.52.4D.


People also ask

What is Jnz?

The JNZ instruction transfers control to the specified address if the value in the accumulator is not 0. If the accumulator has a value of 0, the next instruction is executed. Neither the accumulator nor any flags are modified by this instruction.

What is the difference between JZ and 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.)

What is Jnz back?

Microprocessor8085. In 8085 Instruction set, we are having one mnemonic JNZ a16, which stands for “Jump if Not Zero” and “a16” stands for any 16-bit address. This instruction is used to jump to the address a16 as provided in the instruction.


1 Answers

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.

like image 154
Michael Foukarakis Avatar answered Sep 24 '22 02:09

Michael Foukarakis