LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

How do you recognize a loop in assembly?

Look for a backward conditional jump: a label, a block of body instructions, then a cmp/test + conditional jump that targets that earlier label.

Loop control flow: optional guard for while-loops, body, update (add/sub $1), then a cmp/jcc back-edge to .L_loop marks the loop.

* The tell-tale sign is a backward conditional jump. do-while jumps back from the bottom; while adds a guard jump that skips the body; for adds an init before the loop. *

.L_loop:
    # body instructions
    addl $1, %ecx
    cmpl %edi, %ecx
    jl   .L_loop

Types of loops by structure:

Loop type Pattern
do-while Body first, conditional jump back
while Initial conditional jump to skip, then body + jump back
for Init before loop, body + update + test + jump back

while loop has a guard jump before the loop:

    cmp ...
    je  .L_done
.L_loop:
    # body
    cmp ...
    jne .L_loop
.L_done:

Identifying the loop variable: Look for a register that gets incremented (add $1) or decremented (sub $1) near the conditional jump. The cmp before the jump is the loop condition.

Go deeper:

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