08 CA (Constructing+an+ALU)
08 CA (Constructing+an+ALU)
08 CA (Constructing+an+ALU)
Najeeb-Ur-Rehman
Assistant Professor
Department of Computer Science
Faculty of Computing & IT
University of Gujrat
Subtracting Set to 1 for LSB
BInvert
• Our ALU can add now, but CarryIn Operation
what about subtraction?
• To compute A - B, we can A
0
instead compute A + (-B)
• In 2’s complement, 1 Result
-B = B + 1
• Add an inverter, and a B
B
0
+ 2
1
signal BInvert to get B
• Now, how about that
+1? CarryOut
0 B 0 B
A 0 1 A+1
A 0* 0 A–1
A B 1 A+B+1
A B* 1 A–B
A B 0 A+B
A B* 0 A – B -1
3
Support for SLT BInvert CarryIn Operation
B) < 0 CarryOut
Less will be ‘0’ for bits
Subtract B from A 1-31, special for bit 0
6
Implementing slt instruction
slt C, A, B
0 1 0 0 Reg A
0 0 1 0 Reg B
0 0 0
Adder Adder Adder Adder
0 0 0 Reg C
7
32-bit ALU with Zero detector
8
ALU
000 And
001 Or
010 Add
110 Subtract
10
Problem: ripple carry adder is
slow
Is a 32-bit ALU as fast as a 1-bit ALU?
Is there more than one way to do addition?
two extremes: ripple carry and sum-of-products
Can you see the ripple? How could you get rid of
it?
c1 = b0c0 + a0c0 + a0b0
c2 = b1c1 + a1c1 + a1b1 c2 =
c3 = b2c2 + a2c2 + a2b2 c3 =
c4 = b3c3 + a3c3 + a3b3 c4 =
Not feasible! Why?
11
Carry-lookahead adder
An approach in-between our two extremes
Motivation:
If we didn't know the value of carry-in, what could we
do?
When would we always generate a carry? gi = ai bi
When would we propagate the carry? pi = a i + b i
Did we get rid of the ripple?
c1 = g0 + p0c0
c2 = g1 + p1c1 c2 =
c3 = g2 + p2c2 c3 =
c4 = g3 + p3c3 c4 =
12 Feasible! Why?
Carry Look-Ahead Generator
Sum ABC ABC ABC ABC
Sum A(BC BC) A(BC BC)
Sum A(B C) A(B C)
Sum A B C
13
1-bit Full Adder
Sum A B C
A P
CarryOut C(A B) AB
B
Cin
Cout
14
Carry Generate & Propagate
Sum P C CarryOut CP G
C1 C 0P0 G 0
C 2 C1P1 G1 P1 (C 0P0 G 0 ) G1 G1 P1G 0 P0P1C 0
C 3 G 2 P2 G1 P1P2 G0 P0P1P2 C 0
C 4 G3 P3G 2 P2P3G1 P1P2P3G 0 P0P1P2P3C 0
where
Pn A n B n G n A nB n
15
Look-Ahead Carry Generator
C0
A0 P0
B0
P0
S0
G0
C0
A1 P1
B1 P1
S1
G1
Look-Ahead C1
Carry
A2 P2 Generator
B2 P2
S2
G2
C2
A3 P3
B3 P3
S3
G3
C3
C4
16
Use principle to build bigger
adders CarryIn
a0 CarryIn
b0 Result0--3
a1
b1 ALU0
a2 pi
b2 P0
G0 gi
a3
b3 Carry-lookahead unit
C1
ci + 1
a4 CarryIn
b4 Result4--7
a5
CLA adders
a10 P2 pi + 2
b10 G2 gi + 2
a11
b11
C3
ci + 3
a12
b12
CarryIn
Result12--15
Better: use the CLA principle
again!
a13
b13 ALU3
a14 P3 pi + 3
b14 G3 gi + 3
a15 C4
b15 ci + 4
CarryOut
17