Professional Documents
Culture Documents
Arithmetic
COMP375 Computer Architecture and dO Organization i ti
Elementary School
17 +7 24 010001 +000111 011000
1 Bit Adder
A one bit adder has three inputs, numbers A and B and Carry in. There are two outputs, t t the th Sum S and d Carry C out. t
A B
You add two numbers together. If the sum is greater than the number base, you add one to the next column. When you add two numbers, you may also have to add the carry from the column to the right.
Cout
Cin
Sum
COMP375
Arithmetic Circuits
Cout
Sum
Sum
Sum
figure from textbook
Addition Sum
A B Cin Cin 0 1 A B 1 0 A B 0 1 A B 1 0 Cin Cin
Cout = AB + BC + AC
COMP375
Arithmetic Circuits
Overflow
If operands are too big, then sum cannot be represented as an n-bit 2s complement number.
carry into sign bit carry out of sign bit
(-15)
Detecting Overflow
When the carry into the sign bit does not match the carry out, there is an overflow
COMP375
Arithmetic Circuits
Saving Status
Status flag Overflow Sign Zero Carry Detection XOR of carry into and out of the sign bit Copy of the sign bit NOR of all result bits Carry into the sign bit
1 Bit Subtracter
A one bit subtracter has three inputs, numbers X and Y and Borrow in. There are two t outputs, t t the th Difference Diff and d Borrow B out.
X Y X 0 0 0 0 1 1 1 1
Bin Bin
0 1
1 0
0 1
1 0
Borrowout
Borrowin
Difference
COMP375
Arithmetic Circuits
Bin Bin
0 0
1 0
1 1
1 0
...
X B in + Y ...
B i.. .
Y B in
X Y
B ou t=
B ou t
Subtraction
Instead of building a separate subtraction circuit, you can add the negative of the operand. To make a twos complement number negative, you must invert the bits and add one A NOT gate can be used to invert all the bits. Setting the Carry In on the rightmost bit will add one to the result. A+B+1 = A + (B+1) = A + (-B) = A - B
B ou t
B ou t
X Y
X ..
Carryout
Carryin
COMP375
Arithmetic Circuits
Subtraction Circuit
Propagation Delay
To make a 32 bit adder, you can use 32 one bit adders. dd The left most bit cannot be computed until all of the other bits are computed so that the Carry In value will be known. Each one bit adder requires the signal to go through two gates. Each gate takes a small amount of time to react. This limits the speed of the adder.
COMP375
Arithmetic Circuits
Carry Equations
We can express the carry as: Ci+1 = Gi + (Pi * Ci) Ci+2 = Gi+1 + (Pi+1 * Gi) + (Pi+1 * Pi * Ci) Ci+4 = Gi+3 +(Pi+3 * Gi+2) + (Pi+3 * Pi+2 * Gi+1) + (Pi+3 * Pi+2 * Pi+1 * Gi) + (Pi+3 * Pi+2 * Pi+1 * Pi * Ci)
Reduced Propagation
The simple n bit ripple adder took O(2n) ti time to t add dd n bits bit d due t to carry propagation. ti With carry look ahead, it takes O(3) time to propagate the carry. The look ahead requires more circuitry.
Further Simplification
Creating a big adder out of groups of adders can reduce propagation and circuitry
As Bs As Bs As Bs
Cout
Sums
Sums
Sums
COMP375
Arithmetic Circuits
Multiplication Tables
Decimal
1 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 2 2 4 6 8 10 12 14 16 18 20 3 3 6 9 12 15 18 21 24 27 30 4 4 8 12 16 20 24 28 32 36 40 5 5 10 15 20 25 30 35 40 45 50 6 6 12 18 24 30 36 42 48 54 60 7 7 14 21 28 35 42 49 56 63 70 8 8 16 24 32 40 48 56 64 72 80 9 9 18 27 36 45 54 63 72 81 90 10 10 20 30 40 50 60 70 80 90 100 0 1 0 0 0 1 0 1
Multiplication
543 *312 312 1086 543 1629 169416
decimal
Binary
Binary Multiplication
110 *101 101 110 000 110 11110
101 copy number when bit is one 101 add zero when bit is zero 101 copy number when bit is zero add the results in proper column
COMP375
Arithmetic Circuits
Sequential Logic
The Add and Shift multiplier is not a combinatorial bi t i l l logic i circuit. i it Combinatorial logic has no memory. The output is determined by the input. Sequential logic has memory. The output is determined by the input and what happened previously. Add and Shift multiplier is sequential logic. A
00000
B0 is 1 so Add
A
00101
+
01010
+
00101
B P
00101
00101
00101
COMP375
Arithmetic Circuits
B1 is zero so do nothing
A
01010 00101
B
10100 00101
B
00101
00101
B2 is 1 so Add
A
10100
+
01000 00101
B
00101
B P
11001
11001
COMP375
10
Arithmetic Circuits
B3 is zero so do nothing
A
01000 00101
B
10000 00101
B
11001
11001
B4 is zero so do nothing
A
Done
A
10000 00101
B
10000 00101
B
11001
11001
COMP375
11
Arithmetic Circuits
Combinatorial Multiplier
3 x 3 Example
3 x 3 Example
COMP375
12
Arithmetic Circuits
3 x 3 Example
3 x 3 Example
3 x 3 Example
Division
Division is difficult. (Every elementary school child hild k knows that.) h ) Some small computers do not have multiplication or division. Some have multiplication but not division.
COMP375
13