LOGBOOK

HELP

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.

Flow: sub $0x21 shifts the low bound to zero, cmp $0x5e compares against the width 94, and an unsigned jbe bounds the 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 $0x21 subtracts 33 (the lower bound)
  • cmp $0x5e compares 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:

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