Skip to content
Tutorials Center
My learning

Topics

Lesson 40 of 67 ยท Memory Hierarchy

Byte- and Word-Addressable Memory

Learn what an address names in byte- and word-addressable memory, how to compute address bits and capacity, and how decoders select chips, with Python calculators.

Every byte or word in memory has a number, its address. A question that sounds trivial turns out to matter in exams and in real hardware design: what exactly does one address name? In a byte-addressable memory, one address selects one byte. In a word-addressable memory, one address selects a whole word (2, 4 or 8 bytes). The answer changes how many address bits you need, how big a memory you can reach, and how a program steps through an array.

This lesson gives you the formulas, a calculator to check them, and a look at the decoder that turns address bits into chip selects. It continues from Main Memory Design and Interleaving.

Memory units and powers of two

Capacities are powers of two. Keep these in your head:

Name Symbol Bytes Power of two
Kilo K 1,024 2^10
Mega M 1,048,576 2^20
Giga G 2^30 2^30
Tera T 2^40 2^40
Peta P 2^50 2^50

The standards body uses KiB, MiB, GiB for these binary units and reserves kB, MB, GB for powers of ten. Textbooks and exams usually write K, M and G for the binary sizes.

The shortcut: a memory with 2^n locations needs n address bits. A 64 KiB memory has 2^16 bytes, so a byte-addressable version needs 16 address bits. Writing the size as a power of two (64 K = 2^6 x 2^10) turns every capacity question into addition of exponents.

Byte-addressable memory

Here each address names one byte. A 32-bit word occupies four consecutive addresses, and the address of a word is normally a multiple of 4 (alignment). Almost every modern machine is byte-addressable, because programs work with characters, flags and small integers.

  • Capacity in bytes = 2^(address bits).
  • A CPU with 32 address lines reaches 2^32 bytes = 4 GiB.
  • Word k of 4 bytes starts at address 4k, so stepping through an array of 32-bit integers adds 4 each time.

Word-addressable memory

Here each address names one word. The word size is a property of the machine (16 bits on some small controllers, 36 or 60 bits on old mainframes, 32 on many DSPs).

  • Capacity in words = 2^(address bits); capacity in bytes = 2^(address bits) x bytes per word.
  • Stepping through an array of words adds 1.
  • To fetch a single byte you must read the whole word and select the byte in the CPU, so byte access takes extra instructions (shifts and masks).

The same address width therefore reaches more bytes in a word-addressable design. With 16 address bits and a 4-byte word you reach 2^16 x 4 = 256 KiB, against 64 KiB for byte addressing.

Python Address bits and capacity calculator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Splitting an address

Real memories are built from several chips. The address is split into two groups of bits: the high bits choose a chip (or bank), and the low bits choose a location inside it.

Suppose a computer has a 16-bit byte address and is built from 4 KiB chips. Each chip has 2^12 locations, so 12 low bits go to every chip in parallel. The remaining 4 bits select one of 16 chips. A small circuit called a decoder turns those 4 bits into 16 mutually exclusive chip-select lines: exactly one is active for any address.

flowchart LR
  A["Address bus<br/>A15..A0"] --> HI["A15..A12<br/>(high 4 bits)"]
  A --> LO["A11..A0<br/>(low 12 bits)"]
  HI --> DEC["4-to-16 decoder"]
  DEC -->|"CS0"| C0["Chip 0<br/>4 KiB"]
  DEC -->|"CS1"| C1["Chip 1<br/>4 KiB"]
  DEC -->|"CS15"| C15["Chip 15<br/>4 KiB"]
  LO --> C0
  LO --> C1
  LO --> C15

High bits drive a decoder that enables one chip; low bits go to all chips.

Python Which chip holds this address?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When a memory is bigger than a single chip's width (for example, a 32-bit word built from four 8-bit chips), chips are placed side by side and share the same address, each supplying a slice of the word. Depth (more addresses) is built with decoders; width (more bits per word) is built by putting chips in parallel.

Why it matters

  • Pointers and arrays. In C on a byte-addressable machine, adding 1 to an int * moves 4 bytes. The compiler does the scaling; the hardware only sees byte addresses.
  • Alignment. Reading a 4-byte word at an address that is not a multiple of 4 straddles two memory words. Some CPUs fault, some take two accesses.
  • Instruction sets. Branch offsets in RISC-V and MIPS count bytes (instructions are 4 bytes); some DSPs count words.
  • Address-space limits. A 32-bit byte address limits a process to 4 GiB, which is why 64-bit addresses became necessary.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. How many address bits does a 1 MiB byte-addressable memory need?

    1 MiB = 2^20 bytes, and a byte-addressable memory needs one address per byte, so 20 bits.
  2. 2. A memory has 32 address lines, 16-bit words and is word-addressable. How many bytes can it hold?

    2^32 words x 2 bytes per word = 2^33 bytes = 8 GiB.
  3. 3. In a 64 KiB memory built from 4 KiB chips, how many address bits select the chip?

    64 / 4 = 16 chips, so 4 bits (2^4 = 16). The other 12 bits address inside a chip.
  4. 4. On a byte-addressable machine, what is the address of the 5th element (index 4) of an array of 4-byte integers starting at 0x2000?

    0x2000 + 4 x 4 = 0x2010.
  5. 5. What is the main disadvantage of a word-addressable memory?

    The smallest unit you can address is a whole word, so byte-level data must be extracted in software or extra logic.

Summary

  • A memory with 2^n addressable units needs n address bits.
  • Byte-addressable memory names single bytes; word-addressable memory names whole words, so the same address width reaches more bytes but makes byte access awkward.
  • Convert capacities to powers of two (K = 2^10, M = 2^20, G = 2^30) and add exponents.
  • In multi-chip memories the high address bits drive a decoder that selects a chip, and the low bits select the location inside it.
  • Alignment and the unit of address determine how array indexes and pointers turn into addresses.

Next: Cache Memory Basics.