notes

advertisement
CIT 593 Intro to Computer Systems
Lecture #3 (9/13/12)
Now that we know a bit about computer numbers, we are ready to start understanding how the
computer works. We'll start with the tiniest part – the transistor – and work our way up from there.
Definitions
• transistor: electrical device that either does or does not allow electricity to pass through it
• gate: a combination of transistors that usually performs some logical operation; usually has a
small number of inputs and outputs
• circuit: a combination of gates that may have many inputs and outputs
Types of transistors
You can think of a transistor as an electrical device that has two inputs – the source and the gate (which
is kind of confusing because we're going to use “gate” again for something different, but just go with it
for now) – and one output, which is called the drain.
The source is usually hooked up to some sort of battery or power source (hence the name). If there is a
connection (a “closed circuit”) between the source and the drain, then electrons will flow along the
path.
The gate is used to determine whether the connection is “open” or “closed” between the source and the
drain, and the behavior depends on the type of transistor.
• In an n-type transistor, if the gate is given high voltage, then the transistor acts like a closed
circuit, and electrons can flow from the source to the drain. If the gate is given low (or no)
voltage, the transistor acts like an open circuit, prohibiting the flow of electrons.
• A p-type transistor works in the opposite manner: if the gate is given high voltage, this will act
like an open circuit, stopping the flow of electrons. However, if the gate is given low voltage,
the p-type transistor acts like a closed circuit, and electrons can flow.
Logic Gates
The different types of transistors can be combined in order to achieve boolean/logical functions in the
digital world. That is, we assume that high voltage means “true” or “1”, and low/no voltage means
“false” or “0”, and can use combinations of transistors to implement the logical functions we saw in the
previous lecture. This is called digital logic and the combinations of transistors are referred to as logic
gates (there's that word again!).
A simple example is shown in Figure 3.4 of your textbook. It consists of a p-type transistor and an ntype transistor. When the input is high voltage, then the p-type transistor prohibits the flow of electrons;
the output is connected to the drain through the n-type transistor (which acts like a closed circuit).
Since the drain is at low voltage, so is the output. In this sense, we have “flipped” from a high input
voltage to a low input voltage. For simplicity (and to be more binary), we say we had an input of 1 and
an output of 0.
Likewise, when the input is low voltage (or 0), the p-type transistor acts like a closed-circuit, and
electrons can flow from the source to the output, producing a high voltage or 1. Again, we've “flipped”
the input.
This logic gate, consisting of two transistors, is called a NOT gate because it implements the logical
“NOT” operation (described in Section 2.6 of your textbook). That is, when the input is 1, the output is
0; and when the input is 0, the output is 1.
There are two other important logical operations that we can implement as logic gates, too. Consider
the gate in Figure 3.5. It has two inputs (A and B), and a single output (C). We can create a truth table
indicating what the output is for all the different combinations of the inputs:
A
B
C
0
0
?
0
1
?
1
0
?
1
1
?
Now let's fill this in. When A and B are both 0 (low voltage), the two p-type transistors at the top act as
closed circuits. Electrons can thus flow from the source to the output, so the output is 1. We can update
our truth table as follows:
A
B
C
0
0
1
0
1
?
1
0
?
1
1
?
However, for the other combinations, you can see that one (or both) of the p-type transistors will act as
an open circuit, since it's receiving an input of 1. That means electrons cannot flow to the output from
the source, and the output is thus 0 in all those cases. So our truth table looks like this:
A
B
C
0
0
1
0
1
0
1
0
0
1
1
0
Now look at Figure 3.6. Here, we've taken the logic gate from Figure 3.5 and attached its output to a
NOT gate, thus inverting it. Now the truth table looks like this:
A
B
D
0
0
0
0
1
1
1
0
1
1
1
1
This called an OR gate because it implements the logical operation “OR”. This operation returns 1 if
either A or B is 1, but returns 0 if both are 0.
Keep in mind that usually we say that 1 is “true” and 0 is “false”. So for instance, “false OR true”
would evaluate to “true”. Which makes sense: the sentence “the moon is made of cheese OR
Halloween is October 31” is true, because the second part is true.
Last, consider Figure 3.7. In this case, if either A or B is 0, one (or both) of the p-type transistors will
act as an open circuit, thus connecting the output C to the source and producing an output of 1; if both
are 1, though, both p-type transistors will be open and C will be connected to ground, producing an
output of 0. So we have this truth table:
A
B
C
0
0
1
0
1
1
1
0
1
1
1
0
If, as we did before, we put a NOT gate on the output C, that will invert it, and we'll have the
following:
A
B
D
0
0
0
0
1
0
1
0
0
1
1
1
This is known as an AND gate. It implements the logical operation “AND”, in which the output is 1 if
both A and B are 1, but returns 0 if either is 0.
Logic Circuits
The NOT, OR, and AND gates are very common throughout the world of computer architecture
because the logical operations NOT, OR, and AND are so useful in digital logic. So, rather than
drawing all these transistors, we represent these logic gates with the symbols shown in Figure 3.8 (don't
worry about remembering which is which, everyone always gets them mixed up!).
A combination of gates is referred to as a logic circuit, because the combination will create some
logical operation that has input and output.
A common question is, “given a logic circuit, create its truth table”.
For instance, let's try this one:
This logical circuit represents the operation A = (X AND Y) OR (NOT Z). That is, we have a boolean
expression with three inputs and one output, and in order to create the truth table, we need to figure out
what the output is for each combination of inputs.
We'll start with an empty truth table like this (note that it has eight rows, because we have three inputs
and thus 23 possible combinations):
X
Y
Z
A
0
0
0
?
0
0
1
?
0
1
0
?
0
1
1
?
1
0
0
?
1
0
1
?
1
1
0
?
1
1
1
?
Let's start with the first row, in which X=0, Y=0, and Z=0.
That gives us (0 AND 0) OR (NOT 0).
0 AND 0 is 0, of course.
NOT 0 is 1, of course.
So that gives us 0 OR 1, which is 1. Thus, the output is 1 when all three inputs are 0, and we can fill in
the first row:
X
Y
Z
A
0
0
0
1
0
0
1
?
0
1
0
?
0
1
1
?
1
0
0
?
1
0
1
?
1
1
0
?
1
1
1
?
How about the second row? Now X=0, Y=0, and Z=1.
That gives us (0 AND 0) OR (NOT 1), which is 0 OR 0, which is 0. So now we can fill in the second
row:
X
Y
Z
A
0
0
0
1
0
0
1
0
0
1
0
?
0
1
1
?
1
0
0
?
1
0
1
?
1
1
0
?
1
1
1
?
Easy, right? You can probably figure out the rest on your own.
We can actually speed up this process a bit by noticing something interesting. Whenever Z is 0, the
output will be 1. Why is that? Because no matter what X and Y are, if Z is 0 we'll get (X AND Y) OR
(NOT 0), which is (X AND Y) OR 1, and we know that anything OR 1 will output 1. Cool, huh?
Download