08 CA (Constructing+an+ALU)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Constructing an ALU

CS353 – Computer Architecture

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

– CarryIn to LSB is unused


(always zero) For subtraction:
Set CarryIn of LSB to 1,
– Set it to 1!
Set BInvert to 1
• Subtraction just sets
BInvert and Cin to 1
2
Subtraction a b Cin output
input input input
A 0 0 A

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

• We need to support the


A
SLT operation 0

– Set Result to 1 Result


0000 0000 0000 0000
0000 0000 0000 0001 if A B 0
+ 2
<B 1

 A<B is equivalent to (A - Less 3

B) < 0 CarryOut
Less will be ‘0’ for bits
 Subtract B from A 1-31, special for bit 0

 If the result is negative, then


set LSB of Result to ‘1’, all
others to ‘0’ We’re going to have to do something different
 The result is negative if the for the MSB and the LSB
MSB after the subtraction is
‘1’ (Two’s complement) 4
That tricky MSB BInvert CarryIn Operation
 To properly execute the
SLT, we need to Set the A
0
LSB if the MSB is ‘1’
1
 (After a subtraction)
Result
• Can’t use the ‘Result’ of B 0
+ 2
the MSB 1

– Op will set the Mux to theLess 3

‘Less’ Field MSB Only


Set

– Bring out the adder


output directly: ‘Set’
• Also, we need to check
CarryOut OverFlow
for overflow
– Overflow if Cin to MSB is
different from Cout of MSB
5
Supporting the SLT instruction

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

MUX MUX MUX MUX


Operation

0 0 0 Reg C

7
32-bit ALU with Zero detector

8
ALU

ALU control Function

000 And

001 Or

010 Add

110 Subtract

111 Set on less


than
9
How fast can 32-bit ALU add?
 Carry propagates through the
adders
 64-bit adder slower than 32-bit
adder
 Solution?
 Look-Ahead Carry Generator

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

CarryOut  ABC  ABC  ABC  ABC


CarryOut  C(AB  AB)  AB(C  C)
CarryOut  C(A  B)  AB

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

 Can’t build a 16 bit adder this


b5 ALU1
a6 P1 pi + 1
b6 G1 gi + 1
a7
b7
C2
ci + 2 way... (too big)
 Could use ripple carry of 4-bit
a8 CarryIn
b8 Result8--11
a9
b9 ALU2

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

You might also like