Quiz Entry - updated: 2026.07.06
What does cmpq $0x7, %reg + ja pattern check?
It rejects anything outside 0-7 with one unsigned comparison — negatives wrap to huge unsigned values, so ja catches both "too big" and "negative" at once.
cmpl $0x7, %edi
ja .L_default
This explodes/goes to default if %edi > 7 unsigned. Since negative numbers are huge unsigned values, this simultaneously catches:
- Values > 7 (too large)
- Negative values (wrap to large unsigned)
Where it appears: Almost always as a switch statement bounds check before a jump table.
General pattern: cmp $N, %reg + ja label ensures 0 <= reg <= N in a single check.
Go deeper: