Quiz Entry - updated: 2026.07.06
How do you recognize a range check (e.g., "value must be between 33 and 127") in assembly?
Look for sub $LOW followed by cmp $(HIGH-LOW) and an unsigned jump (jbe/ja) — one comparison that bounds a value on both sides at once.
* One unsigned comparison bounds both sides: sub $LOW, then cmp $(HIGH-LOW) + jbe. A value below the low bound wraps to a huge unsigned number and fails the ≤ 94 test. *
sub $0x21, %eax
cmp $0x5e, %eax
jbe ok_label
call <explode_bomb>
This checks 33 <= original_value <= 127:
sub $0x21subtracts 33 (the lower bound)cmp $0x5ecompares with 94 (range width: 127 - 33)jbe= unsigned "below or equal"
Why unsigned? If the original value was below 33, the subtraction wraps around to a huge positive number (unsigned), which fails the <= 94 check. This single comparison handles both bounds at once.
General pattern: sub $LOW, %reg + cmp $(HIGH-LOW), %reg + jbe checks LOW <= value <= HIGH.
Go deeper:
Jcc — conditional jump reference (felixcloutier) — Shows exactly which flags jbe/ja test, confirming why the unsigned jump catches the wrapped-around underflow.
Control flow (Wikipedia) — Background on how high-level conditionals map to branch instructions; on-topic Wikipedia anchor for the diagram.