19

I have the next instruction:

cmp al, 1
jz mub

When al is 2 (10 in binary). What would do this instruction? As I know, I can use JE,JNE,JA etc., but what is meaning jz after cmp instruction?

Thanks

1
  • jz = je, it's the same instruction. Feb 18, 2012 at 18:34

3 Answers 3

29

jz is "jump if zero". cmp subtracts its two operands, and sets flags accordingly. (See here for reference.)

If the two operands are equal, the subtraction will result in zero and the ZF flag will be set.

So in your sample, the jump will be taken if al was 1, not taken otherwise.

5

jz means jump if zero. In this context, it will only jump if al was 1.

That's because cmp is usually equivalent to sub (subtract) but without actually changing the value.

cmp al, 1 will set the processor flags (including the zero flag) based on what would have happened if you'd subtracted 1 from al.

If al is 2, the jump will not be taken (because the zero flag has not been set) and code will continue to execute at the instruction following the jz.

As an aside, jz is often the same opcode as je since they effectively mean the same thing. See for example the Wikipedia page on x86 control flow:

Jump on Zero
jz loc
Loads EIP with the specified address, if the zero bit is set from a previous arithmetic expression. jz is identical to je.

1

'Jump Zero' - jump to label 'mub' if the zero flag is set. 'cmp' is a subtract that only sets flags & so, if al is 2, (2-1)<>0 so the zero flag is clear and the jump will not be performed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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