Lesson 6: Memory & the Memory Hierarchy
Last lesson every circuit was memoryless — the output was set only by the current inputs. Now we cross an important boundary: sequential logic — circuits that remember. Their output depends not only on the inputs but also on a state stored within them from the past. We'll start with the smallest sto
Until now we saw circuits that forget instantly. Now we'll build circuits that remember: a flip-flop holding one bit, fast registers in the CPU, and large RAM. And we'll see why we keep the most-used data close and fast in a cache.
- Sequential Logic
- A circuit whose output depends both on the current inputs and on a state stored within it from the past — that is, a circuit with memory. The opposite of combinational logic.
- Latch
- A basic sequential circuit that can hold a single bit: you can 'latch' a 0 or 1 into it and it stays until changed.
- Flip-Flop
- A one-bit storage unit that updates in step with the clock. A D-type flip-flop 'captures' the input value at the clock tick and holds it until the next tick.
- Register
- A small group of flip-flops (e.g. 8, 32, or 64) that holds a whole value inside the CPU. It is the fastest memory in the computer.
- RAM (Random Access Memory)
- A large array of memory cells, each directly addressable by an address — to read or write the byte in that cell. Volatile: erased on power-off.
- Address
- A number identifying a specific cell in memory. You give an address and get (or write) the value in that cell, like an apartment number in a building.
- Volatile
- A property of memory that loses its contents the moment power is cut. RAM is volatile; disk and SSD are non-volatile.
- Cache
- A very small, very fast memory close to the CPU (L1/L2/L3) that keeps a copy of frequently used data to avoid a slow trip to RAM.
- Memory Hierarchy
- The memory ladder by speed, size, and cost: registers -> cache (L1/L2/L3) -> RAM -> SSD/disk. The faster a level is, the smaller and costlier it is.
- Locality of Reference
- The tendency of programs to access again the data they just used, or nearby data. Thanks to it, a small cache 'guesses' well what will be needed soon.