LOGBOOK

HELP

Quiz Entry - updated: 2026.07.06

How do you recognize a switch statement / jump table in assembly?

Look for an unsigned bounds check (cmp + ja) followed by an indirect jump through a table, jmp *table(,%reg,8).

Unsigned bounds check (cmp $6, ja default), then indirect jmp *.L4(,%rdi,8) reads an 8-byte target from a .rodata table and dispatches to a case.

* Bounds check with ja, then an indirect jump through a table of 8-byte .quad addresses. Each table entry is one case; *8 because addresses are 8 bytes on x86-64. *

cmp  $6, %rdi
ja   .L_default
jmp  *.L4(,%rdi,8)

The pattern:

  1. Bounds check: cmp $N, %reg + ja default — ensures index is 0..N
  2. Indirect jump: jmp *table(,%reg,8) — jumps through a table of addresses
  3. Jump table in .rodata: array of .quad addresses, one per case

How to read the jump table in GDB:

(gdb) x/8a 0x402500
0x402500: 0x400e73  (case 0)
0x402508: 0x400e90  (case 1)
...

Why *8? Each entry is a 64-bit address (8 bytes) on x86_64.

Key insight: Compilers use jump tables when switch cases are dense (few gaps). Sparse cases get compiled as if-else chains instead.

Go deeper:

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