Professional Documents
Culture Documents
Arithmetic
a
32 ALU
result
32
b
32
2
Constructing an ALU (Arithmetic Logic Unit)
A 0
C
B 1
ALU (Cont.)
op a b res
operation
a
result
b
4
The 1-bit Logical Unit for AND and OR
Operation
Result
1
b
Different Implementations
• Not easy to decide the “best” way to build something
– Don't want too many inputs to a single gate
– Don’t want to have to go through too many gates
– for our purposes, ease of comprehension is important
• Let's look at a 1-bit ALU for addition:
C a rr y In
• A full adder or a (3,2) adder
has three inputs (a, b, & Cin)
a
and two outputs (Sum & Cout).
Sum
• A half adder or a (2,2) adder
b
has only 2 inputs (a & b) and 2
outputs (Sum & Cout).
C a rry O u t
• How could we build a 1-bit ALU for Add, AND, and OR?
• How could we build a 32-bit ALU?
6
Input and Output Specification for 1-bit Adder
Inputs Outputs
a b CarryIn CarryOut Sum
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
Inputs
a b CarryIn
0 1 1
1 0 1
1 1 0
1 1 1
8
Adder Hardware for the Carry Out Signal
CarryIn
CarryOut
10
A 1-bit ALU that Performs AND, OR, & Addition
O p e r a t io n
C a rry In
a
0
1
R e s u lt
2
b
C a rry O u t
11
a2 C a rry In
R e s u lt 2
A LU 2
b2
C a rry O u t
a31 C a rry In
R e s u lt 3 1
A LU 31
b31
12
What about subtraction (a – b) ?
1
Result
b 0 2
CarryOut
13
14
Detecting Overflow
value Less
Supporting slt (A 1-bit ALU for the most significant bit)
C a r ry In
the most significant bit that has
an extra output bit: the adder
a
output. 0
b 0 2
• As long as we need a special
1
ALU for the most significant
bit, we added the overflow Less 3
b.
17
a0 C a rry In
b0 ALU0 R e s u lt0
Le ss
C a rry O u t
a1 C a rry In
b1 ALU1 R e s u lt1
0 Le ss
C a rry O u t
a2 C a rry In
b2 ALU2 R e s u lt2
0 Le ss
C a rry O u t
C a r ry In
18
Test for equality [ (a – b = 0) Æ a = b ]
Bnegate Operation
• The simplest way is to OR
all the outputs together and
a0 CarryIn
then send that signal b0 ALU0
Result0
Less
through an inverter as CarryOut
19
Control Lines
000 = and
001 = or
010 = add
110 = subtract
111 = slt
20
The Symbol Commonly Used to Represent an ALU
ALU operation
a
ALU Zero
result
b Overflow
CarryOut
21
Conclusion
22
Problem: Ripple Carry Adder is Slow
Can you see the ripple? How could you get rid of it?
23
25
26
Carry Lookahead Adder (Continue)
G0= g3+(p3.g2)+(p3.p2.g1)+(p3.p2.p1.g0)
G1= g7+(p7.g6)+(p7.p6.g5)+(p7.p6.p5.g4)
G2= g11+(p11.g10)+(p11.p10.g9)+(p11.p10.p9.g8)
G3= g15+(p15.g14)+(p15.p14.g13)+(p15.p14.p13.g12)
27
C1= G0 + (P0.c0)
C2= G1 + (P1.G0) + (P1.P0.c0)
C3= G2 + (P2.G1) + (P2.P1.G0) + (P2.P1.P0.c0)
C4= G3 + (P3.G2) + (P3.P2.G1) + (P3.P2.P1.G0) + (P3.P2.P1.P0.c0)
28
Four 4-bit ALUs using Carry Lookahead to form
a 16-bit adder
C a r r y I n
a 0 C a r r y I n
b 0 R e s u lt 0 - - 3
a 1
b 1 A L U 0
a 2 p i
b 2 P 0
G 0 g i
a 3
b 3 C a r r y - l o o k a h e a d u n it
C 1
c i + 1
a 4 C a r r y I n
b 4 R e s u lt 4 - - 7
a 5
b 5 A L U 1
a 6 P 1 p i + 1
b 6 G 1 g i + 1
a 7
b 7
C 2
c i + 2
a 8 C a r r y I n
b 8 R e s u lt 8 - - 1 1
a 9
b 9 A L U 2
a 1 0 P 2 p i + 2
b 1 0 G 2 g i + 2
a 1 1
b 1 1
C 3
c i + 3
a 1 2 C a r r y I n
b 1 2 R e s u lt 1 2 - - 1 5
a 1 3
b 1 3 A L U 3
a 1 4 P 3 p i + 3
b 1 4 G 3 g i + 3
a 1 5 C 4
b 1 5 c i + 4
C a r r y O u t
29
• Determine the gi, pi, Pi, and Gi values of these two 16-
bit numbers:
a: 0001 1010 0011 0011two
b: 1110 0101 1110 1011two
• Also, what is CarryOut 15 (C4)?
30
Answer (Continue)
• Next, the “super” propagates (P3, P2, P1, P0) are simply the AND
of the lower-level propagates:
P3 = 1 . 1 . 1. 1 = 1
P2 = 1 . 1 . 1. 1 = 1
P1 = 1 . 1 . 1. 1 = 1
P0 = 1 . 0 . 1. 1 = 0
• The “super” generates are more complex, so use the following
equations:
G0 = g3 +(p3.g2)+(p3.p2.g1)+(p3.p2.p1.g0)
= 0 +(1.0)+(1.0.1)+(1.0.1.1)= 0
G1 = g7 +(p7.g6)+(p7.p6.g5)+(p7.p6.p5.g4)
= 0 +(1.0)+(1.1.1)+(1.1.1.0)= 1
G2 = g11 +(p11.g10)+(p11.p10.g9)+(p11.p10.p9.g8)
= 0 +(1.0)+(1.1.0)+(1.1.1.0)= 0
G3 = g15 +(p15.g14)+(p15.p14.g13)+(p15.p14.p13.g12)
= 0 +(1.0)+(1.1.0)+(1.1.1.0)= 0
31
Answer (Continue)
• Finally, CarryOut 15 is
C4 = G3 +(P3.G2)+(P3.P2.G1)+(P3.P2.P1.G0)
+(P3.P2.P1.P0.c0)
= 0+(1.0)+(1.1.1)+(1.1.1.0)+(1.1.1.0.0)=1
32
Example: Speed of Ripple Carry versus Carry Lookahead
33
Answer
CarryIn
CarryOut
• The above figure shows that the carry out signal takes
two gates delays per bit.
• Then the number of gate delays between a carry in to
the least significant bit and the carry out to the most
significant is 16 x 2 = 32.
34
Answer (Continue)
35
Multiplication
1000 (multiplicand)
__x_1001 (multiplier)
1000
0000
0000
1000
1001000 (Product)
• If we ignore the sign bits, the length of the multiplication of
an n-bit multiplicand and an m-bit multiplier is a product that
is n + m bits long.
• That is, n + m bits are required to represent all possible
products.
36
Multiplication
37
Multiplicand
Shift left
64 bits
Multiplier
64-bit ALU Shift right
32 bits
Product
Control test
Write
64 bits
38
First Version of the Multiplication Hardware
39
M u lt ip li e r 0 = 1 1 . T e s t M u l t ip li e r 0 = 0
M u l t ip li e r 0
1 a . A d d m u lt ip li c a n d t o p r o d u c t a n d
p la c e th e r e s u lt in P r o d u c t r e g is t e r
3 . S h ift th e M u l t ip li e r r e g is t e r r i g h t 1 b it
N o : < 3 2 r e p e t i t io n s
3 2 n d r e p e t iti o n ?
Y e s : 3 2 r e p e titio n s
D o n e
40
The First Multiplication Algorithm
41
43
44
Second Version of the Multiplication Hardware
Multiplicand
32 bits
Multiplier
32-bit ALU Shift right
32 bits
Shift right
Product Control test
Write
64 bits
45
46
Second Multiplication Algorithm Using the Hardware in
Slide 45
S ta rt
M u l t ip li e r 0 = 1 1 . T e s t M u l t ip li e r 0 = 0
M u lt ip li e r 0
1 a . A d d m u lt ip l ic a n d t o t h e le ft h a lf o f
t h e p r o d u c t a n d p la c e th e r e s u lt in
th e le f t h a lf o f t h e P r o d u c t r e g i s t e r
2 . S h if t t h e P r o d u c t r e g is t e r r ig h t 1 b it
3 . S h if t t h e M u lt i p l ie r r e g is t e r r i g h t 1 b it
N o : < 3 2 r e p e t i t io n s
3 2 n d r e p e titio n ?
Y e s : 3 2 r e p e t i tio n s
D o n e
47
50
Third Version of the Multiplication Hardware
Multiplicand
32 bits
32-bit ALU
51
52
The Third Multiplication Algorithm
S ta rt
P ro d u c t0 = 1 1 . T e s t P ro d u c t0 = 0
P ro d u c t0
1 a . A d d m u lt i p l ic a n d t o t h e le f t h a lf o f
th e p r o d u c t a n d p la c e th e r e s u lt in
t h e le f t h a lf o f t h e P r o d u c t r e g i s t e r
2 . S h if t t h e P r o d u c t r e g is t e r r ig h t 1 b it
N o : < 3 2 r e p e ti t io n s
3 2 n d r e p e t it io n ?
Y e s : 3 2 r e p e t it io n s
D o n e
53
54
Example: Third Multiply Algorithm
55
Signed Multiplication
56
Booth’s Algorithm
57
Booth’s Algorithm
58
Booth’s Algorithm
59
60
Comparing Example (Continue)
61
62
Multiply in MIPS
63
64