LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

How is a do-while loop translated to assembly, and why is it considered the most fundamental loop form?

It becomes "label: Body; if (Test) goto label;" — body first, then a conditional jump back.

Control-flow graph with the body running first, a test, and a conditional back-edge jumping to the body top while true, else falling out.

* do-while: body first, then one conditional back-edge — the raw hardware loop shape. *

A do-while runs its body, then checks the condition, looping back while it's true:

do { Body } while (Test);

Goto / assembly shape:

.L_loop:
    # Body
    cmpq ...        # evaluate Test
    jne  .L_loop    # if true, jump back and repeat

Why it's the canonical form: This maps exactly onto what hardware offers — straight-line code followed by one conditional backward branch. There's no separate "loop" instruction needed. Because of this, compilers convert every while and for loop into do-while form internally (adding a guard test where needed). If you can recognize the "body, then conditional jump backward to the body's top" pattern in disassembly, you've found a loop.

Note: Test is an integer expression: 0 means false, anything non-zero means true — the same convention C uses.

Go deeper:

From Quiz: REVE1 / Translation of C to Assembly | Updated: Jul 10, 2026