Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [66]
Or the byte 99h could actually be the number 99 in decimal! This has a certain appeal to it, of course, but it seems to violate everything we've learned so far. I'll explain how it works in Chapter 23. But next I must talk about memory.
Chapter 16. An Assemblage of Memory
As we rouse ourselves from sleep every morning, memory fills in the blanks. We remember where we are, what we did the day before, and what we plan to do today. These memories might come in a rush or a dribble, and maybe after some minutes a few lapses might persist ("Funny, I don't remember wearing my socks to bed"), but all in all we can usually reassemble our lives and achieve enough continuity to commence living another day.
Of course, human memory isn't very orderly. Try to remember something about high school geometry, and you're likely to start thinking about the kid who sat in front of you or the day there was a fire drill just as the teacher was about to explain what QED meant.
Nor is human memory foolproof. Indeed, writing was probably invented specifically to compensate for the failings of human memory. Perhaps last night you suddenly woke up at 3:00 A.M. with a great idea for a screenplay. You grabbed the pen and paper you keep by your bed specifically for that purpose, and you wrote it down so you wouldn't forget. The next morning you can read the brilliant idea and start work on the screenplay. ("Boy meets girl w. car chase & explosions"? That's it?) Or maybe not.
We write and we later read. We save and we later retrieve. We store and we later access. The function of memory is to keep the information intact between those two events. Anytime we store information, we're making use of different types of memory. Paper is a good medium for storing textual information, and magnetic tape works well for music and movies.
Telegraph relays too—when assembled into logic gates and then flip-flops—can store information. As we've seen, a flip-flop is capable of storing 1 bit. This isn't a whole lot of information, but it's a start. For once we know how to store 1 bit, we can easily store 2, or 3, or more.
In Chapter 14, we encountered the level-triggered D-type flip-flop, which is made out of an inverter, two AND gates, and two NOR gates:
When the Clock input is 1, the Q output is the same as the Data input. But when the Clock input goes to 0, the Q output holds the last value of the Data input. Further changes to the Data input don't affect the outputs until the Clock input goes to 1 again. The logic table of the flip-flop is the following:
Inputs Outputs
D
Clk
Q
Q-bar
0
1
0
1
1
1
1
0
X
0
Q
Q-bar
In Chapter 14, this flip-flop was featured in a couple of different circuits, but in this chapter it will be used in only one way—to store 1 bit of information. For that reason, I'm going to rename the inputs and outputs so that they'll be more in accordance with that purpose:
This is the same flip-flop, but now the Q output is named Data Out, and the Clock input (which started out in Chapter 14 as Hold That Bit) is named Write. Just as we might write down some information on paper, the Write signal causes the Data In signal to be written into or stored in the circuit. Normally, the Write input is 0 and the Data In signal has no effect on the output. But whenever we want to store the Data In signal in the flip-flop, we make the Write input 1 and then 0 again. As I mentioned in Chapter 14, this type of circuit is also called a latch because it latches onto data. Here's how we might represent a 1-bit latch