Skip to content

Computer Architecture

How does ROM work? Read-only memory explained

ROM, read-only memory, takes an address and gives back the word stored there. Inside, a decoder lights one word line per address, and each output bit is an OR of the word lines whose word has a 1 in that bit. The pattern of connections is the data. It's fixed when the chip is made, so it's still there after the power goes off.

Decoder first

A 2-bit address picks one of four word lines. Line 0 is NOT A1 AND NOT A0, line 1 is NOT A1 AND A0, line 2 is A1 AND NOT A0, and line 3 is A1 AND A0. Exactly one is lit at a time. An address of n bits reaches 2ⁿ words: 3 bits, 8 words; 16 bits, 65,536.

ORs make the bits

Store 5, 3, 6 and 0 at addresses 0 to 3:

1s = line 0 OR line 1 · 2s = line 1 OR line 2 · 4s = line 0 OR line 2

5 is 101, so line 0 joins the 4s OR and the 1s OR. 3 is 011: the 2s and the 1s. 6 is 110: the 4s and the 2s. Address 3 holds 0, so its line joins nothing, and when it's lit every OR gives 0. Changing the data changes only the joins, never the decoder.

Live experiment

Solder your own ROM

A counter steps the address, the decoder lights one word line, and each data bit is an OR of the lines joined to it. Tick through 5, 3, 6, 0, then tap the crossings to solder diodes in and out: join line 3 to all three ORs and address 3 holds 7.

Try it yourself: free lesson

“Read-only memory” is lesson 4 of 6 in Program Peninsula, Computer Architecture World 3. Free with an account. Lessons unlock in order, so you’ll do the 17 before it first.

A grid of diodes

Early ROMs were literally this grid: word lines crossing bit lines, with a diode soldered at every crossing where the word has a 1. Diodes from several word lines into one bit line make a diode OR: whichever line is high pulls the bit high, and the diodes stop it pulling the other lines up. Mask ROMs made the same grid in silicon, with the pattern set by one of the chip's last layers.

Fetch: a counter on the address

Put a counter on the address lines and every tick reads the next word: 5, 3, 6, 0, and round again. That's the fetch step of every processor, with the program counter addressing program memory and the word that comes back being the next instruction.

From ROM to flash

EPROMs could be erased with ultraviolet light through a quartz window in the chip, EEPROMs electrically, a byte at a time. Flash is their descendant: read like a ROM, rewritten in blocks. An Arduino's sketch lives in flash, which Upload rewrites, and old game cartridges were plain mask ROMs, which is why the games never changed.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“Read-only memory” is lesson 4 of 6 in Program Peninsula, Computer Architecture World 3. Free with an account. Lessons unlock in order, so you’ll do the 17 before it first.

Or start from the very first lesson, no account needed

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3Address 3 holds 0. Its word line joins…
    Show the answer

    Answer: No OR at all, so it isn't needed. A word of all zeros has no 1 to make. With no line lit, every OR gives 0 anyway.

    • Why not “The 4s OR”? Joined to the 4s OR, address 3 would read 100, which is 4.
    • Why not “The 1s OR”? Joined to the 1s OR, address 3 would read 001, which is 1.
    • Why not “Every OR”? Joined to every OR, address 3 would read 111, which is 7.
  2. Question 2 of 3A ROM's data bit is an OR of…
    Show the answer

    Answer: The word lines whose word has a 1 in that bit. Each line joins the ORs for the 1s in its word.

    • Why not “Every word line”? An OR of every word line is 1 at every address, so that bit could never be 0.
    • Why not “The other data bits”? Data bits don't feed each other. Each one comes straight from the word lines.
    • Why not “The address bits”? The address goes through the decoder first. Each data bit depends on which word line is lit.
  3. Question 3 of 3The decoder's three ANDs each take…
    Show the answer

    Answer: One pattern of Q0, Q1 and their NOTs. FETCH: NOT Q0 AND NOT Q1. DECODE: Q0 AND NOT Q1. EXECUTE: NOT Q0 AND Q1. One hot line per state.

    • Why not “Only NOTs”? Only NOTs spots just the pattern 00. Each AND takes each bit either straight or through a NOT.
    • Why not “The clock”? A decoder is combinational: it looks at the bits, not at the clock.
    • Why not “Q0 and Q1 straight”? Q0 AND Q1 straight only spots the pattern 11. The other patterns need NOTs on the bits that are 0.
Keep practising: free lesson

“Read-only memory” is lesson 4 of 6 in Program Peninsula, Computer Architecture World 3. Free with an account. Lessons unlock in order, so you’ll do the 17 before it first.

Questions people ask

What is ROM used for?

Holding things that must survive power-off and rarely change: a microcontroller's program, a computer's start-up firmware, character shapes for a display, lookup tables. Today most of these live in flash, a rewritable kind of ROM.

What is the difference between ROM and RAM?

ROM keeps its contents with the power off and isn't written in normal use. RAM can be written as easily as it's read, but forgets everything when the power goes. A computer starts from ROM or flash and works in RAM.

How many words can a ROM hold?

Two to the power of its address bits. A 3-bit address reaches 8 words, 10 bits reach 1,024 and 16 bits 65,536. Each word is as wide as the ROM's number of data outputs.

Every topic