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.