awesome-everything RU
↑ Back to the climb

Base CS from zero

Addressable cells

Crux Memory is one long row of numbered storage cells. The address is the cell''''s number; the value is what sits in the cell. The CPU asks for a cell by giving its address.
◷ 18 min

When a program stores a number, the machine has to put it somewhere. But “somewhere” is too vague — the machine needs a precise, unambiguous location so it can find that number again later. How does it achieve that precision?

The answer is beautifully simple: memory is organised as a long, straight row of storage cells, and every cell has a number — its address. To find a cell, you name its number. The CPU asks for address 42 and gets back whatever sits in cell 42. No searching, no guessing. Just: “give me cell number 42.”

This single idea — numbered cells — is the foundation of how every computer stores and retrieves data.

Goal

After this lesson you can describe memory as a row of numbered cells, distinguish an address from a value, and explain in concrete terms what it means for the CPU to read from or write to a memory address.

1

Memory as a row of cells. Computer memory (RAM — Random Access Memory) is physically built from many tiny circuits that each hold one bit. For practical use, these bits are grouped and the groups are laid out in a straight sequence like seats in a very long row. Each group is a memory cell — a storage slot that holds a value.

The word “cell” is deliberate: think of a grid cell in a spreadsheet, or a mailbox in a post office. Each cell is a container. Its content can change (you can overwrite it), but the cell itself is permanently fixed at its position in the row. The row has a definite start (the very first cell) and a definite length (the total number of cells the machine has).

2

The address: a cell’s permanent number. Every cell in the row has a unique number, starting from 0. This number is called the cell’s address. Address 0 is the first cell, address 1 is the second cell, address 2 is the third, and so on up to the last cell.

The address is not stored inside the cell — it is the cell’s position in the row, like a house number on a street. The house number does not change when new tenants move in; similarly, address 7 always refers to the seventh cell regardless of what value that cell currently holds.

Because addresses start at 0, a memory with N cells has addresses 0 through N−1. If a machine has 1 000 cells, the valid addresses are 0 to 999. Asking for address 1 000 would be out of range — there is no cell there.

3

The value: what sits in a cell. The value is the content of a cell — the actual data stored there. A value can change at any time: you write a new value and the old one is gone. But the address of the cell never changes.

This separation is crucial:

  • Address: which cell. Fixed. A location.
  • Value: what is in that cell. Variable. The data.

A single cell at address 12 might hold the value 0 right now and the value 255 five milliseconds later — the cell’s identity (address 12) is constant, but its contents changed.

Why this works

Why start addresses at 0 rather than 1? In hardware, an address is a binary number, and the first valid address is the one where all bits are 0 — which is the number 0. Starting at 1 would mean the address 0 is unused, wasting one position and complicating the arithmetic. Starting at 0 makes the address of cell N exactly N, which simplifies every calculation involving offsets. Most programming languages follow the same convention for array indices.

4

Reading from memory: the CPU asks by address. To retrieve a stored value, the CPU performs a memory read. It puts the address it wants onto the address bus (a set of wires connecting the CPU to memory), the memory hardware locates the cell at that address, and the value stored there is returned to the CPU on the data bus.

The key insight: the CPU never scans through cells looking for a value. It names the address directly and gets the cell immediately. That is what “random access” means in “RAM” — you can access any cell directly by its address in roughly the same amount of time, without traversing the cells before it.

5

Writing to memory: the CPU sends address and value. A memory write is the reverse: the CPU sends both an address and a new value. The memory hardware locates the cell at that address and stores the new value there, overwriting whatever was there before. The cell now holds the new value until another write changes it again.

A write is destructive in one sense: the previous value is gone with no record. If you need the old value, you must read it before writing the new one.

17
0
0
1
255
2
42
3
8
4
200
5
1
6
99
7
Eight memory cells at addresses 0–7. The highlighted cell at address 3 holds the value 42. A CPU read of address 3 returns 42.
Worked example

Walking through a read and a write.

Suppose a program needs to add two numbers stored in memory and save the result.

State before any operation:

  • Address 10 holds value 25
  • Address 11 holds value 30
  • Address 12 holds value 0 (will hold the result)

Step 1 — Read address 10. The CPU sends address 10 to memory. Memory returns 25. The CPU now has 25 in a register (a small storage spot inside the CPU itself).

Step 2 — Read address 11. The CPU sends address 11 to memory. Memory returns 30. The CPU now has both 25 and 30.

Step 3 — Add. The CPU adds 25 + 30 = 55. This happens inside the CPU; memory is not involved in the arithmetic itself.

Step 4 — Write address 12. The CPU sends address 12 and value 55 to memory. Memory stores 55 at address 12, overwriting the old value 0.

State after:

  • Address 10: 25 (unchanged)
  • Address 11: 30 (unchanged)
  • Address 12: 55 (updated)

Nothing about addresses 10 or 11 changed. Only the cell that was written changed.

Common mistake

A common confusion is thinking that an address and a value are the same kind of thing because both are numbers. They are not. The address is a location identifier — it tells the machine where to look. The value is the data stored at that location. Address 42 is not the same as a cell whose value happens to be 42. You can have address 42 holding value 7, or address 7 holding value 42 — four combinations, each different.

Practice 0 / 5

Memory has cells at addresses 0 through 7. How many cells does it have? Type the number.

A cell at address 5 holds the value 99. After writing the value 0 to address 5, what value does address 5 hold?

A cell at address 3 holds value 42. What value does a read of address 3 return?

Memory has addresses 0 through 255. What is the address of the very first cell?

After a write of value 7 to address 10, and then a write of value 3 to address 10, what value does a read of address 10 return?

Check yourself
Quiz

What does a CPU memory read operation require as input, and what does it return?

Recap

Computer memory is a long, straight row of cells, each identified by a unique number called its address. Addresses start at 0 and increase by 1 for each successive cell. The value is the data currently held in a cell — it can change, but the address is fixed. A memory read takes an address and returns the value stored there. A memory write takes an address and a new value and stores that value in the cell, overwriting whatever was there before. The CPU reaches any cell directly by its address without scanning — that direct accessibility is what “random access” means.

Continue the climb ↑The byte
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.