Lesson 3 of 9 · 23m
Control Flow: Reading Disassembly as a Graph
Turn linear disassembly into basic blocks and branches so loops, conditions, and compiler-generated control flow become legible.
Assembly is printed as a list, but programs do not execute as a list. They execute as a graph. If you read top to bottom without marking jump targets, you will misunderstand loops, inverted conditions, and jump tables. The senior habit is to find basic blocks first and meaning second.
Start with branches and labels
cmp edi, 10
jge large
mov eax, 1
ret
large:
mov eax, 2
retThe basic blocks end at branches, returns, and jump targets. Here there are two outcomes: edi < 10 returns 1; otherwise execution falls into large and returns 2. The label is not magic; it is simply a target address.
Conditions are often inverted
C source says:
if (len < 16) copy_small(buf, len);Assembly often tests the negation and jumps over the body:
cmp esi, 16
jge done
call copy_small
done:This pattern matters because the jump condition may look backwards compared with the source. Read it as "jump away when the if-body should not run."
Loops are just backward branches
xor eax, eax
loop:
add eax, [rdi+rcx*4]
inc rcx
cmp rcx, rsi
jb loop
retThe backward branch jb loop is the loop back edge. Identify induction variables, exit conditions, and which comparison is signed or unsigned. jb is unsigned; jl is signed. That one letter changes vulnerability analysis.
Jump tables encode switch statements
cmp edi, 5
ja default
mov eax, edi
lea rcx, [rip+table]
movsxd rdx, dword [rcx+rax*4]
add rdx, rcx
jmp rdxA bounded index selects a branch target. The prior ja default is the bounds check. When auditing parser dispatch, missing or malformed bounds checks are more important than the jump mechanics.
Build a reading ritual
First scan for ret, call, jumps, and labels. Then mark function arguments and memory references. Only after that assign meaning. Names like sub_401130 are invitations to build evidence, not verdicts.
Field notes
jmpis unconditional; conditional jumps depend on flags set by a prior instruction.callpushes a return address;retpops it. Mismatches are catastrophic, not cosmetic.- Tail calls often compile to
jmp functioninstead ofcallfollowed byret. - Compilers duplicate blocks for performance, so one source line can appear in several places.
- Linear disassemblers can misinterpret embedded data as code; control-flow-aware tools are safer.
Was this lesson helpful?