Computer Systems Org I - Prof. Grishman
Lecture 25 - Nov. 29, 2004
Computer logic: building combinational circuits from gates
A combinational circuit is a logic circuit in which each output is a
Boolean function of its inputs. Such a circuit can be represented
in three ways:
A half-adder does binary addition for a single bit. It has two
inputs, x and y, and two outputs, sum and carry. The truth table
for the half-adder is
- by a truth table, listing each combination of inputs and the
- by a Boolean formula for each output
- by a circuit diagram, connecting a set of logic gates
The Boolean formulas are
= (x AND (NOT y)) OR ((NOT x) AND y) = x EXCLUSIVE-OR y
carry = x AND y
We can verify these formulas by computing their value for each
combination of inputs, and seeing if they match the listed
outputs. But how can such a formula be systematically produced,
starting from the truth table?
The simplest approach is to produce what is called a sum-of-products formula. The
formula consists of a bunch of terms
which are connected by ORs. Each term consists of a bunch of
factors, one for each input. Each factor represents either an
input, or a negated input. There will be one term for each row of
the truth table with a "1" output.
In the simple case where there are two inputs, x and y, and one
output, we generate the formula as follows:
if there is more than one row with output = 1, OR the corresponding
look only at rows with output = 1
for each such row, build a term as follows:
if x = 0, include (NOT x) in the term
if x = 1, include x in the term
if y = 0, include (NOT y) in the term
if y = 1, include y in the term
AND these factors together to build the term
This simple procedure doesn't always produce the simplest formula, but
it will always produce a correct formula corresponding to the truth
table. The truth table can be used to represent any Boolean
function, so this procedure shows that one can compute any Boolean
function using only AND, OR, and NOT gates (P&P sec. 3.3.5:
A half-adder is fine for adding 1-bit binary numbers. But if we
are adding larger numbers, then for every place except the low-order
bit, we have to take into account the carry in coming from the position
to the right. A full adder is a one-bit binary adder with allows
for a carry in, so it has 3 inputs: x, y, and carry-in.
The truth table and circuit diagram for a full adder are shown in
P&P, page 62.
To add n bits, we connect together n adders. The rightmost adder
can be either a half adder or a full adder with the carry-in
permanently tied to 0. The adders are connected together with the
carry out of one bit feeding the carry in of the next bit, as shown on
p. 63 of P&P.
A multiplexer selects one of two inputs (or, more generally, n inputs)
and sends that to the output. The circuit for a two-input
multiplexer is shown on p. 61 of P&P.
An ALU (Arithmetic-Logic Unit) takes two n-bit inputs and a function
input, and computes one of a small number of arithmetic or logical
functions of the two inputs. The ALU is the heart of any
computer. For the LC-3, it has to compute three functions:
ADD, AND, and NOT.
The design of an ALU is very simple: we build a separate circuit
for each. Then we build a multiplexer which selects the output of
the appropriate circuit.