← again tap: answer good → ↑ swipe up at the end: next
Question
After cmp A, B in AT&T syntax, how do you read the conditional jump?
Answer
Read it as "jump if B (condition) A" — cmp A, B computes B - A, so the condition is about the second operand relative to the first.
* cmp A, B computes B - A, so the conditional jump reads as B relative to A (not A relative to B). *
cmp $5, %eax
jl label
Reads as: "jump if %eax < 5"
cmp %ebx, %eax
jge label
Reads as: "jump if %eax >= %ebx"
Why? cmp A, B computes B - A and sets flags. The conditional jump then tests those flags as if asking about B relative to A.
Common mistake: Reading it as "A < B" because A comes first — but AT&T source-destination order means A is subtracted FROM B.
Go deeper:
CMP instruction reference — confirms cmp subtracts the second operand from the first and sets the same flags as SUB.
Jcc conditional-jump reference — shows exactly which flags each jl/jge/etc tests after the compare.
Question
What is the difference between je/jne and jz/jnz?
Answer
They are the same instruction — je/jz are two names for one opcode (jump if ZF=1), and jne/jnz for another (jump if ZF=0).
| Name | Alias | Meaning | Flag checked |
|---|---|---|---|
je |
jz |
Jump if equal / zero | ZF = 1 |
jne |
jnz |
Jump if not equal / not zero | ZF = 0 |
Use je/jne after cmp (comparing two values). Use jz/jnz after test or arithmetic (checking if result is zero). The assembler doesn't care — it's purely a readability convention.
Go deeper:
Jcc reference (JE/JZ aliases) — shows JE and JZ share one opcode (74 short / 0F 84 near) and both test ZF, confirming they are aliases.