But How Do It Know? - the Basic Principles of Computers for Everyone (4 page)

BOOK: But How Do It Know? - the Basic Principles of Computers for Everyone
10.77Mb size Format: txt, pdf, ePub

The only difference between this picture and the picture of our original gate is that the little circle after the big ‘D’ is missing.

Since ‘x’ is not used, the chart can also be simplified, and it looks like this:

 

 
a

 

 
b

 

 
c

 

 
Off

 

 
Off

 

 
Off

 

 
Off

 

 
On

 

 
Off

 

 
On

 

 
Off

 

 
Off

 

 
On

 

 
On

 

 
On

The only difference between this chart and the chart of our original gate is that every item in column ‘c’ is the opposite of what it was in the original chart.

Imagine that this combination of gates was installed in that room with the two light switches and the ceiling light. The only way the light could be on is if both switches were on. So if you walked in there and saw the light on, and then looked at the switches, you would see that they were both on. No matter which switch you decided was for the light, and you switched it off, the light would go off. You might not notice that if you turned both off, and then wanted to turn the light back on, you wouldn’t be able to do it by just flipping one switch. You would have to go through the same experiment, flipping both switches until the light came on, and you would find that one switch
and
the other switch would have to be on to get the light to light.

This combination gate could be described this way: For the output to be on, one input AND the other input must both be on. Thus this type of gate has a name, and in the tradition of the informal terminology invented by computer people, because it reminds us of what the word AND means, it is simply called an “AND gate.”

Now to fill in a few details purposely left out above, the original gate we looked at works like the AND gate except the output is the opposite, or the negative of the AND gate. Thus it is called a Negative AND gate, or just a “NAND gate” for short.

The simple gate that had both inputs tied together also has its own name. The output is always the opposite of the one input, that is, if the input is on, the output is not on (off.) If the input is off, the output is not off (on.) The output is always NOT what the input is, thus, it is called a “NOT gate.”

Notice the difference between the diagrams of the AND gate and the NAND gate. They are the same except that there is a little circle at the beginning of the output of the NAND gate. The thing that looks like a large letter ‘D’ means to do the ‘AND’ function, which means to take action only if both inputs are on, and the little circle means switch to the opposite. So an AND gate is on if both inputs are on, a NAND gate is off if both inputs are on. The NOT gate starts with a triangle, which just means take the input and turn it into an output. The circle then means to switch to the opposite.

The AND gate is used a lot in computers, and it is probably the easiest to understand, but we looked at the NAND gate first for two reasons. The first and less important reason is that the NAND gate is the easiest gate to build. When you have to build a large number of gates, it will be cheaper and more reliable if you can use the type of gate that is easiest to build.

The second, and very important reason that we looked at the NAND gate first is this: That everything in a computer that makes it a computer, can be made out of one or more NAND gates. We have already seen that the NOT gate and the AND gate can be made out of NAND gates, and we will see a few more interesting combinations as we go along. But every one of them is based on this silly little thing called a NAND gate.

The problem in this chapter has been that the NAND gate is the basic building block of computers, but the AND gate is the first gate that has a name that makes sense. So we looked first at the NAND gate and the NOT gate without giving them names. Then we built an AND gate, gave it its name, and went back and named the first two.

As a note on the language here, the word ‘and’ is a conjunction in regular English. It connects two things, as in “I like peas and carrots.” In computers, we use the word in two new ways. First, it is an adjective, a word that modifies a noun. When we say “this is an AND gate,” the word “gate” is a noun, and the word “AND” tells us what kind of a gate it is. This is how “AND” has been used in this chapter. “AND” will also be used as a verb, as in “let us AND these two bits.” We will see AND used in this way later in the book.

So back to the simplicity theme of this book, we have said that there is only one thing in computers, bits. And now we see that bits are constructed using gates, and all gates come down to the NAND gate. So all you have to know to understand computers is this very simple device, the NAND gate. No kidding! Can you understand this thing? Then you can understand the whole computer.

 

Diagrams

If you want to see how a mechanical machine works, the best way to do it is to look inside of it, watch the parts move as it operates, disassemble it, etc. The second best way is to study it from a book that has a lot of pictures showing the parts and how they interact.

A computer is also a machine, but the only thing that moves inside of it is the invisible and silent electricity. It is very boring to watch the inside of a computer, it doesn’t look like anything is happening at all.

The actual construction of the individual parts of a computer is a very interesting subject, but we are not going to cover it any further than to say the following: The technique starts with a thin crystal wafer, and in a series of steps, it is subjected to various chemicals, photographic processes, heat and vaporized metal. The result is something called a ‘chip,’ which has millions of electronic parts constructed on its surface. The process includes connecting the parts into gates, and connecting the gates into complete computer sections. The chip is then encased in a piece of plastic that has pins coming out of it. Several of these are plugged into a board, and there you have a computer. The computer we are going to ‘build’ in this book could easily fit on one chip less than a quarter of an inch square.

But the point is, that unlike a mechanical machine, the actual structure of a chip is very cluttered and hard to follow, and you can’t see the electricity anyway. The diagrams we saw in the previous chapter are the best way to show how a computer works, so we’d better get pretty good at reading them.

Throughout the rest of this book, we are going to build new parts by connecting several gates together. We will describe what the new part does, and then give it a name and its own symbol. Then we may connect several of those new parts into something else that also gets a name and a symbol. Before you know it, we will have assembled a complete computer.

Every time there is a new diagram, the text will explain what its purpose is, and how the parts achieve it, but the reader really must look the diagram over until it can be seen that the gates actually do what the book says they will do. If this is done faithfully with each one, you will very shortly see exactly how a computer works.

There are only two things in our drawings, there are parts that have inputs and outputs, and there are lines, or wires, that connect outputs and inputs together.

When electricity comes out of the output of a gate, the electricity travels through the whole wire as fast as it can go. If the output of a gate is on, then the electricity is on in the wire that is connected to it, for as far as it goes. If the output of a gate is off, the whole wire is off. I guess you could consider that the bit that comes out of the gate includes the whole wire as well.

The inputs of gates do not use up the electricity in the wire, so one output may be connected to the input of one or many gates.

When wires are connected together, this is shown by a dot where they meet on the diagram, and all wires that are connected together get electricity as if they were one wire. When wires cross on a diagram without a dot, it means that there is no connection between them, they are not touching, the two bits are separate.

Whenever there is a choice, the diagrams will show the path of the electricity moving from left to right, or from the top of the page towards the bottom. However, there will be many exceptions to this, especially later on in the book. But you can always tell which way the electricity is moving in a wire by starting at an output and following it to an input.

Most of the diagrams in the book are very easy to follow. In a few cases, there will also be one of those charts that shows what the output will be for every possible combination of inputs. If you have trouble following a diagram, you can pencil in the ons and offs right on the page, or place coins on the page and flip them so that heads means on and tails means off.

Unfortunately, the diagram in the next chapter is probably the hardest one to follow in the whole book, but once you master it, you’ll be an expert diagram reader.

 

Remember When

You have probably heard of computer memory, and now we are going to see exactly what that is. Since the only thing inside of computers is bits, and the only thing that happens to bits is that they either turn on or turn off, then it follows that the only thing a computer can ‘remember’ is whether a bit was on or off. We will now see how that is accomplished.

The following diagram shows one bit of computer memory. It happens to be one of the neatest tricks you can do with a few gates. We will examine how it works here at great length, and after we understand it, we will replace it with its own symbol, and use it as a building block for bigger and better things.

It is made of only four NAND gates, but its wiring is kind of special. Here it is:

This combination as a whole has two inputs and one output. ‘I’ is where we input the bit that we want to remember, and ‘o’ is the output of the remembered bit. ‘S’ is an input that tells these gates when to ‘set’ the memory. There are also three internal wires labeled ‘a’, ‘b’ and ‘c’ that we will have to look at to see how these parts work together. Try to follow this carefully, once you see that it works, you will understand one of the most important and most commonly used things in a computer.

To see how this works, start with ‘s’ on and ‘i’ off. Since ‘i’ and ‘s’ go into gate 1, one input is off, so ‘a’ will be on. Since ‘a’ and ‘s’ go to gate 2, both inputs are on, and therefore ‘b’ will be off. Looking at gate 4, since ‘b’ is off, the output of gate 4, ‘c’ will be on. Since ‘c’ and ‘a’ are both on, the output of gate 3, ‘o’ will be off. ‘O’ goes back down to gate 4 providing a second off input, leaving ‘c’ still on. The important thing to note here is that with ‘s’ on, ‘o’ ends up the same as ‘i.’

Now with ‘s’ still on, lets change ‘i’ to on. Since ‘i’ and ‘s’ go into gate 1, ‘a’ will be off. ‘A’ goes to one side of both gate 2 and gate 3, therefore their outputs ‘o’ and ‘b’ must both be on. ‘O’ and ‘b’ both on go into gate 4 and turn ‘c’ off, which goes back up to gate 3 providing it with a second off input, leaving ‘o’ still on. The important thing to note here is the same thing we noted in the previous paragraph - that with ‘s’ on, ‘o’ ends up the same as ‘i.’

So far, we have seen that when ‘s’ is on, you can change ‘i’ on and off, and ‘o’ will change with it. ‘O’ will go on and off just the same as ‘i.’ With ‘s’ on, this combination is no more useful than a wire connecting ‘i’ to ‘o.’

Now let’s see what happens when we turn ‘s’ off. Look at gate 1. When ‘s’ is off, ‘a’ will be on no matter what you do to ‘i.’ Now you can switch ‘i’ on and off and nothing will happen. The same goes for gate 2. ‘A’ may be on, but ‘s’ is off, so ‘b’ can only be on. Both ‘a’ and ‘b’ are on, and changing ‘i’ does nothing. Now the only thing left that matters, the big question is, what will ‘o’ be?

If ‘i’ and ‘o’ were on before ‘s’ got turned off, gate 3 had both inputs off, and gate 4 had both inputs on. When ‘s’ goes off, ‘a’ comes on, which is one input to gate 3. But the other input is off, so nothing changes, ‘o’ stays on.

If ‘i’ and ‘o’ were off before ‘s’ got turned off, gate 3 had both inputs on, and gate 4 had both inputs off. When ‘s’ goes off, ‘b’ comes on, which is one input to gate 4. But the other input is off, so nothing changes, ‘c’ stays on and ‘o’ stays off.

So the answer to the question of what happens to ‘o’ when ‘s’ is turned off, is that it stays the way it was, and it is no longer affected by ‘i.’

Now what do we have here? With ‘s’ on, ‘o’ does whatever ‘i’ does. With ‘s’ off, ‘o’ stays the way it and ‘i’ were, at the last instant just before ‘s’ went off. Now ‘i’ can change, but ‘o’ stays the way it was. This combination of gates locks in the way ‘i’ was at an earlier time. This is how a combination of four NAND gates can “remember.” This is only one bit of memory, but this is the basic building block of all computer memory. All that computer memory is, is a way of preserving the way a bit was set at some point in time.

Other books

A Phantom Affair by Jo Ann Ferguson
The Volcano Lover by Susan Sontag
The Baby Truce by Jeannie Watt
Whispering Spirits by Rita Karnopp
A Study in Revenge by Kieran Shields
Desiring the Enemy by Lavelle, Niecy
Seven Seasons in Siena by Robert Rodi