LOGBOOK

HELP

Quiz Entry - updated: 2026.07.06

How do you recognize an if-else branch in assembly?

Look for cmp + a conditional jump (often with the condition inverted) to an else label, with an unconditional jmp at the end of the then-block that skips over the else-block.

If-else in assembly: cmp then an inverted conditional jump to .L_else; the then-block falls through and ends with jmp .L_end to skip the else-block; both paths merge at .L_end.

* Inverted-condition jump to the else label; the then-block falls through and jumps past the else to the merge point. *

    cmp  %rsi, %r8
    jl   .L_else
    # then-branch code
    ...
    jmp  .L_end
.L_else:
    # else-branch code
    ...
.L_end:
    ret

The structure:

  1. Condition test: cmp + conditional jump
  2. Then block: code that runs if condition is false (fall-through)
  3. jmp past else: unconditional jump to skip the else block
  4. Else block: code that runs if condition is true (jumped to)
  5. Merge point: both paths converge

Important: The compiler often inverts the condition. If the C code says if (a >= b), the assembly might use jl .L_else (jump to else if a < b). The then-block is the fall-through path.

Simple if (no else):

    cmp  %rsi, %rdi
    jle  .L_skip
    # if-body (only runs when rdi > rsi)
.L_skip:

No jmp at the end — there's no else block to skip over.

Go deeper:

From Quiz: REVE1 / Assembly Patterns & GDB | Updated: Jul 06, 2026