Professional Documents
Culture Documents
1 1 1 0 0 0 0 0 CARRY
1 1 0 1 0 1 0 0 X
1 0 1 1 0 0 1 0 Y
1 1 0 0 0 0 1 1 0 SUM
0 0 0 1 1 1 1 0 BORROW
1 1 0 1 1 0 0 0 X
0 1 0 0 1 1 0 1 Y
1 0 0 0 1 0 1 1 DIFFERENCE
1 0 0 0 1 1 1 0 0 BORROW
0 1 0 1 0 0 0 1 X
1 1 0 0 1 0 1 0 Y
1 0 0 0 0 1 1 1 DIFFERENCE
000 000
111 0 001 111 0 001
7 1 7 1
5 3 5 3
101 4 011 101 4 011
100 100
100 - 100 = 000 000 - 111 = 001
-2 1110 -2 1110
+6 0110 -5 1011
+4 0100 -7 1001
1111 0000 0001 1111 0000 0001
1110 -1 0 1 0010 1110 -1 0 1 0010
-2 2 -2 2
1101 0011 1101 0011
-3 3 -3 3
-2+6
1100 -4 4 0100 1100 -4 -2-5 4 0100
-5 5 -5 5
1011 -6 6 0101 1011 -6 6 0101
1010 -7 -8 7 0110 1010 -7 -8 7 0110
1001 0111 1001 0111
1000 1000
l Note that in one case there is a carry out and in the other there is not
Elec 326 6.12 Binary Arithmetic & ALUs
n Two's Complement Subtraction
u Add the two's complement of the subtrahend to the minuend.
= B⊕(A⊕CI)
= A⊕B⊕CI CO
CO = A•CI + B•CI + A•B = MAJ(A, B, CI)
xor(s, x, y, Cin);
and(z1, x, y);
and(z2, x, Cin);
and(z3, y, Cin);
or(Cout, z1, z2, z3);
endmodule
l Altera software does not support xor gate module. How would you get around that
limitation?
u A behavioral specification:
module fulladd(Cin, x, y, s, Cout);
input Cin, x, y;
output s, Cout;
assign s = x ^ y ^ Cin;
assign Cout = (x & y) | (x & Cin) | (y & Cin);
endmodule
endmodule
CO ADDER CI
CO FA FA FA FA CI
n
S3 S2 S1 S0 S
tADD = n¥tCICO
endmodule
l Comment: the specification of fulladd can be included in the same file as the
adder4 or in a different one if its location is known
parameter n = 4;
wire [n-1:0] W
endmodule
NOT n
B
...
n n
NOT
CO ADDER 1 n
n
D
XOR
B
n n n
FA
M
M
FA M
M
FA M
M
FA M
M
Carry Sum
Generation Generation
C1 = A0•B0+A0•C0+B0•C0
= A0•B0+(A0+B0)•C0
M
C2 = A 1•B1+A1•C1+B1•C1
= A1•B1+(A 1+B1)•(A0•B0+(A0+B0)•C0)
M = A1•B1+(A 1+B1)•A0•B0+(A1+B1)•(A0+B0)•C0
C3 = A2•B2+A2•C2+B2•C2
= A2•B2+(A 2+B2)•(A1•B1+(A1+B1)•A0•B0+(A1+B1)•(A0+B0)•C0)
M = A2•B2+(A2+B2)•A1•B1+(A2+B2)•(A1+B1)•A0•B0+
(A2+B2)•(A1+B1)•(A0+B0)•C0
Carry
Generation
C1 = G0 + P0 • C0
C2 = G1 + P1 • C1 = G1 + P1 •(G0 + P0 • C0)
= G1 + P1 • G0 + P1 • P0 • C0
C3 = G2 + P2 • C2 = G2 + P2 •(G1 + P1 • G0 + P1 • P0 • C0)
= G2 + P2 • G1 + P2 • P1 • G0 + P2 • P1 • P0 • C0
C4 = G3 + P3 • C2
= G3 + P3 •(G2 + P2 • G1 + P2 • P1 • G0 + P2 • P1 • P0 • C0)
= G3 + P3 • G2 + P3 • P2 • G1 + P3 • P2 • P1 • G0 + P3 • P2 • P1 • P0 • C0
= G + P • C0
where G = G3 + P3 • G2 + P3 • P2 • G1 + P3 • P2 • P1 • G0
and P = P3 • P2 • P1 • P0
u Note that this expression has only three levels of delay for all i.
u Note also that the number of variables in the product term grows
with i.
u These equations are used to define carry look ahead logic as
illustrated in the following figures.
C1 P G
P G
X1
ADD1 S1
Y1
Carry
P1 G1
Look
Ahead u The 74S182 is a commercial CLA chip
Logic C2
X2
ADD1 S2
u These carry look ahead networks can be
Y2
P2 G2
connected to extend the technique to
more than four bits in the following way.
C3
X3
ADD1 S3
Y3
P3 G3
P G
CLA
FA FA FA FA FA FA FA FA
6.5. Pitfalls
o Viewing the carry out as an overflow/underflow for two's
complement addition/subtraction.