Académique Documents
Professionnel Documents
Culture Documents
Goals
By the end of this lecture, you should understand How to build a Half-Adder How to build a Full-Adder How to use Adders to perform subtraction
N301: Fundamental Computer Science Concepts
Copyright 2004 Department of Computer & Information Science
What We Can Do
Last time, we learned how to build a circuit that met functional requirements. Today, lets build a circuit that performs a specific engineering function and supports two output lines well build a circuit to add two binary numbers
Problem Definition
We will start out simply, adding two single digit binary numbers Lets make certain we can do this by hand before we construct the circuit There are four possible combinations of single digit, two number addition:
0 + 0 =0 0+1=1 1+0=1 1 + 1 = 10
N301: Fundamental Computer Science Concepts
Copyright 2004 Department of Computer & Information Science
Problem Analysis
Notice that one of the combinations of two single digit additions is a double digit number, created by a carry: 1 + 1 = 10
Standardized Output
Well use leading zeros in order to produce a standard output: 0 + 0 = 00 (0 plus 0 equals 0) 0 + 1 = 01 (0 plus 1 equals 1) 1 + 0 = 01 (1 plus 0 equals 1) 1 + 1 = 10 (1 + 1 equals 10) Notice that all of our answers include two bits. By putting the output in standardized form, we can stipulate the behavior of both outputs given any combination of two inputs with the following truth table
N301: Fundamental Computer Science Concepts
Copyright 2004 Department of Computer & Information Science
OUTPUTS
R 0 1 1
Notice the Q column (carry line) from the truth table? Recognize it? Its an AND!: Q=AB
What about the R column (sum line)? What sub-expression could we use? What do you notice about the R column? R is high iff one and exactly one input is high
Circuit Diagram
Q = (~A B) + (A ~B)
A
Q B
A Short Cut
The circuit we created to diagram our R column is so common in circuit design that it has a special name. It is called an Exclusive Or. It is usually labeled XOR or drawn as a plus sign with a circle around it. From our truth table, we can derive the following statement: Our adding circuit should consist of an XOR gate (for R output, the Sum line) and an AND gate (for Q output, the Carry line).
More on XOR
We have already established that any circuit can be created as a combination of 3 basic gates: NOT, AND and OR. Although not one of the fundamental gates, the XOR gate is common enough that it is called a derived gate. We can build the XOR from the primitive gates. However, engineers use the XOR so often theyve given XOR its own symbol
N301: Fundamental Computer Science Concepts
Copyright 2004 Department of Computer & Information Science
XOR Symbol
The symbol for the XOR Gate:
A
Q
B
Q = A+B
N301: Fundamental Computer Science Concepts
Copyright 2004 Department of Computer & Information Science
0
0 1 1
0
1 0 1
0
0 0 1
0
1 1 0
A RSUM
QCARRY
Full Adder
Lets try to add 3 single digit numbers by stringing together two half-adders:
We need 3 input lines, one for each number. Two input lines feed into the first half adder; the third input line functions as a carry-in line. The second half-adder has two input lines: the output sum from the first half-adder, plus the third, carry-in input line.
The next slides show the truth table for the Full Adder and then the circuit diagram for the Full Adder
N301: Fundamental Computer Science Concepts
Copyright 2004 Department of Computer & Information Science
A
0 0 0 0 1 1
B
0 0 1 1 0 0
CIN
0 1 0 1 0 1
QCARRY
0 0 0 1 0 1
RSUM
0 1 1 0 1 0
1
1
1
1
0
1
1
1
0
1
B
QCARRY
CIN
B
CIN
FULL ADDER
RSUM
Getting Real
The processing component of the ALU the arithmetic logic unit uses Adder circuitry to perform fundamental arithmetic operations. By connecting half adders to make a full adder, and multiple full adders in a chain, we now can work our way to simple addition. Other operations are a variation on this fundamental capability
How to Subtract
What other arithmetic operations do we need to be able to perform with circuits? The next logical step would be to tackle subtraction We could come up with a separate subtraction circuit, and some clever scheme of knowing which circuit to activate based on what kind of math problem we encountered It turns out that the solution is more elegant -- it uses the approach we have seen repeatedly: turn a new problem into a problem we have already solved
Twos Complement
Remember that we can represent negative numbers using a scheme called Twos Complement. In twos complement, to encode a negative number, you take its positive value, complement it, and then add one. The resulting number will be in twos complement form.
N301: Fundamental Computer Science Concepts
Copyright 2004 Department of Computer & Information Science
Problem Solution
Then, we add the first number of our problem (510 or 01012) to this twos complemented number: 01012 + 11102 = 100112 If we throw away the carry line (the leftmost 1), our answer is correct: 00112 = 310 Is that legal? Why or why not? We are restricting ourselves here to 2, 4-bit numbers. We can choose to simply ignore the carry line (the 5th bit).
N301: Fundamental Computer Science Concepts
Copyright 2004 Department of Computer & Information Science
The next step would be to add one we could use an addition circuit, to make certain one was added. Now we have the twos complemented number, and it is combined with the first number in an adder circuit to produce an answer.
Pretty Close
This is pretty close to how subtraction is actually performed in a computer. There are a few tweaks for efficiency and minimal circuit design The second step of twos complement requires you to add one, and we could do this with an adder. However, do you remember how we built our multi-bit adder by stringing together multiple adders?
N301: Fundamental Computer Science Concepts
Copyright 2004 Department of Computer & Information Science
Summary of Subtractors
Represent the subtraction problem as an addition problem by adding a negative value of the number. We can represent negative numbers using Twos Complement. Once we have converted the subtraction problem to an addition problem, we can use an adder, built from a half-adder consisting of an And and an XOR gate.
N301: Fundamental Computer Science Concepts
Copyright 2004 Department of Computer & Information Science
Questions?