Skip to content
BetterDL

Address range

Also called: address block, block of addresses, last address, first and last address, end address

The span of addresses from a first to a last address, inclusive. A block of N words starting at S ends at S + N − 1, and S to E holds E − S + 1 words.

An address range is a run of consecutive addresses, written first–last, such as 4000₁₆–7FFF₁₆. Both ends are included.

Two formulas do almost all the work:

  • Size of a range: from S to E there are E − S + 1 words.
  • End of a block: N words starting at S end at S + N − 1.

Both contain the same off-by-one: the +1 or −1 accounts for counting the first address. (Fence posts 3 to 5 are three posts, not two.) See off by one error.

Tricks that make hex ranges easy:

  • A whole memory (or a block starting at 0) ends at all 1s: a 2K memory ends at 7FF₁₆, a 64K one at FFFF₁₆.
  • Add 1 to an end address finishing in F digits and you get a round number, which makes subtraction easy: 3FFF₁₆ + 1 = 4000₁₆.
  • Sizes in hex: 1K = 400₁₆, 2K = 800₁₆, 4K = 1000₁₆, 8K = 2000₁₆, 16K = 4000₁₆, 32K = 8000₁₆.

Ranges are the building blocks of a memory map.

5
16³
F
16²
F
16¹
F
16⁰

Worked examples

Example

Where does a 4K block end?

A 4K block starts at 5000₁₆.

  1. 1.

    4K = 4096 = 1000₁₆, so size − 1 = FFF₁₆.

  2. 2.

    Last address = 5000₁₆ + FFF₁₆ = 5FFF₁₆ (the diagram).

  3. 3.

    Check: the next block would start at 5FFF₁₆ + 1 = 6000₁₆ = 5000₁₆ + 1000₁₆. ✓

Example

How many words in a range?

Range 2C00₁₆ to 2FFF₁₆, inclusive.

  1. 1.

    2FFF₁₆ − 2C00₁₆ = 3FF₁₆.

  2. 2.

    Add 1: 400₁₆ = 1024 words = 1K.

  3. 3.

    Quicker: the range ends just before 3000₁₆, so it holds 3000₁₆ − 2C00₁₆ = 400₁₆ words.

Common mistakes

  • Forgetting the +1. 2000₁₆ to 2FFF₁₆ is 1000₁₆ words, not FFF₁₆.

  • Ending a block at start + size. That's the first address of the next block.

  • Doing the subtraction in decimal digits. Hex borrows in 16s; convert or count carefully.

Practice Address range

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Address range is taught in Memory.