Topic 10: How Computers Work, Part 5
April 23, 2004

Outline
Introduction
- We have seen a simple model of a computer at a very low level,
showing registers, the ALU, memory, and even the machine
language with which it may be programmed.
- But what are the building blocks that make up components such as
the ALU?
Back to Contents
Simple Logic Gates
- You may recall that two of the operations in our simple ALU were
bitwise-AND and bitwise-OR, that is, take each bit of a two
registers and AND or OR them together
- How would we perform this operation on two bits?
- Using special components designed to perform logical
operations
- There are three fundamental logical operations
- These three operations can be used to derive ALL the other simple
operations that an ALU carries out, including addition and
subtraction
- They are implemented in hardware using special circuits called
gates
The AND gate
- symbolically the AND operation is represented by a dot,
much like multiplication
- the gate itself is represented by the following diagram
- and you recall that the following is a truth table for AND
(here we are substituting a 1 for 'true' and 0 for 'false')
Truth Table for AND Gate
| input 1 | input 2 | output |
| | |
|
 |  |
| | |
| | |
The OR gate
- symbolically the OR operation is represented by a plus,
much like addition
- the gate itself is represented by the following diagram
- and you recall that the following is a truth table for OR
Truth Table for OR Gate
| input 1 | input 2 | output |
| | |
|
 |  |
| | |
| | |
The NOT gate
- symbolically the NOT operation is represented by a horizontal
bar placed over the value to be negated
- the gate itself is represented by the following diagram
- and you recall that the following is a truth table for NOT
Truth Table for NOT Gate
| input | output |
| |
|  |
Final Notes on Simple Gates
- Both AND gates and OR gates can have more than two
inputs
- commercial gates tend to have 2, 3, or 4 inputs, but usually
don't go higher
Back to Contents
Derived Logic Gates
- While we could do everything with ANDs, ORs, or NOTs, there
are some combinations of these that are used so often that they
have been given names and logic symbols of their own
The NAND gate
- this is an AND gate followed by a NOT
- symbolically the NAND operation is represented by a dot,
with a bar over the entire expression
- the gate itself is represented by the following diagram
- the following is a truth table for NAND
Truth Table for NAND Gate
| input 1 | input 2 | output |
| | |
|
 |  |
| | |
| | |
The NOR gate
- this is an OR gate followed by a NOT
- symbolically the OR operation is represented by a plus,
with a bar over the entire expression
- the gate itself is represented by the following diagram
- the following is a truth table for NOR
Truth Table for NOR Gate
| input 1 | input 2 | output |
| | |
|
 |  |
| | |
| | |
The XOR gate
- The operation of the exclusive-OR gate may be described
as "output 1 if either input 1 or input 2 is 1, but output 0 if
both are the same"
- symbolically the OR operation is represented by a plus sign with a circle around it
- the gate itself is represented by the following diagram
- the following is a truth table for XOR
Truth Table for XOR Gate
| input 1 | input 2 | output |
| | |
|
 |  |
| | |
| | |
- unlike the other gates (other than NOTs) XORs always have
2 inputs
Back to Contents
Combining Logic Gates
- How can we produce the derived logic gates from our simple gates?
- The NAND and NOR gates are rather obvious
- an AND gate
immediately followed by a NOT gate
- or an OR gate
immediately followed by a NOT gate
- What about the XOR gate?
- Note that XOR is logically equivalent to
NOT A AND B OR A AND NOT B
- Let's examine the first circuit diagram on the Deriving the XOR Gate Page(from www.play-hookey.com)
- However, because this circuit uses three types of gates, it is
cumbersome to construct on a printed circuit board
- Ideally, we would like to construct it out of only one type
of gate
- The solution is to use a series of NAND gates
- indeed, most operations can be specified using this technique
Combinatorial vs. Sequential Logic Gates
- combinatorial logic circuits
- Logic gates that only depend upon the current logic states of all
inputs
- this is what we
have been working with so far
- sequential logic circuits
- Circuits that "remember" the past states of their inputs and use
this information along with current inputs to produce outputs are
called
- They are named because they act in accordance
with a sequence of input signals
- Such circuits can be used to construct registers and other
memory elements
- We will only talk about combinatorial logic circuits here
Back to Contents
Building An Adder
- As our last example, let us look at building a circuit to correctly add
multi-bit numbers
- Recall when we talked about adding binary numbers, I mentioned
we could think about the sum of 1+1 as being 0, carry the 1
- This leads to the following truth table:
- See the first table on the Binary Addition Page (from
www.play-hookey.com)
- What operation do the SUM and CARRY columns correspond to ????
- Thus we can add two bits together with the following circuit
- Are we done? Think about the following addition : 111+ 001
- At the moment, we are not considering the carry from
the previous addition in our circuit
- If we wish to add numbers with more than one bit, we
need to handle this
- Thus, the circuit we just went through is only a half
adder
- We would actually need three inputs to create a full adder
- the first bit to be added
- the second bit to be added
- the carry from any previous addition
- We will not go over it, but we can indeed build such a circuit
by selecting from our set of simple and derived logic gates
Back to Contents
SUM and CARRY Columns
- the SUM is the result of an XOR operation and the
CARRY is the result of an AND operation
Back to Building an Adder