How does a computer remember
So far we've used gates to calculate. But when a gate's input goes away, its output disappears right along with it. So how does a computer remember a value? There's a very clever trick.
Let go and it's gone
Gates have one weakness.
They only give an output while an input is coming in.
Press a button and a light comes on, but the moment you let go, it goes off.
Press and release the button below and you'll see the difference right away.
The light stays on only while you hold the button down.
That way you can calculate, but you can't remember.
You can make a number for a moment, but it vanishes as soon as you let go.
You need another way to hold on to a value.
Feed its own output back in
The clever trick is to send a gate's output back into its own input.
Then something curious happens.
Once it's on, that "on" signal keeps switching itself on, so the state holds even after the input is gone.
The output loops back to the input.
This feedback loop is the heart of memory.
Like two people standing back to back and leaning on each other, the circuit holds up its own state.
Put a value in and it stays
With this feedback circuit we build a cell that remembers one value.
Press the "remember" button and it becomes 1; press the "clear" button and it becomes 0.
The important part is that the value stays even after you take your finger off the button.
Put in a value and let go: the value stays.
The value stays after you let go. That's memory.
This tiny cell is called a flip-flop.
The name comes from the way one tap flips it to one side, where it stays.
Write it down, read it later
Memory proves its worth after time has passed.
Write a value now (write), check it again much later (read), and it's still there.
This "write and read" is the basic action behind all storage.
Press play and you'll see writing, waiting, and reading happen in order.
Write, wait, read.
A value you've written can still be read after time goes by.
Thanks to this simple agreement, a computer can hold on, for a while, to the calculation it just did and the letters you just typed.
Gather lots of these cells and you have memory
One flip-flop remembers 1 bit: a single 0 or 1.
Gather eight and you have one character (1 byte); gather tens of millions and you can store a photo or a song.
A real computer's main memory uses even smaller capacitor cells, but the principle is the same: each cell holds on to a 0 or a 1.
Below, you can switch the cells on one by one.
Each cell is 1 bit.
Circuits that calculate (adders) and circuits that remember (flip-flops) are the two pillars of a computer.
In the lessons ahead, we'll see how each memory cell gets a label (an address) so the computer can go straight to the cell it wants.