Lecture13 PDF
Lecture13 PDF
Lecture 13: 1
Announcements
• Lab 4 prelab (B) due tomorrow
Lecture 13: 2
Example: Fixed Size 2’C Addition
• White stone = 0
• Black stone = 1
Lecture 13: 3
Review: Full Adder
A
B S
Cin A B
Cout Cin
S
Cout
OR
FA
Lecture 13: 4
Building a Binary Adder
1 1 1 0 0 0 0 0
carries
01101000 (A)
+ 11110000 (B)
01011000 (S)
Lecture 13: 5
Four Bit Adder
1 1 0 0 0
1100
+0110
0010
a3 b3 a2 b2 a1 b1 a0 b0
A B A B A B A B
c4 c3 c2 c1 0
Cout Cin Cout Cin Cout Cin Cout Cin
S S S S
s3 s2 s1 s0
01101000 (104)
- 00010001 (17)
01101000 (104)
+ 11101111 (-17)
01010111 (87)
Lecture 13: 7
Four Bit Subtractor
b3 b2 b1 b0
negating the
second operand
b3’ b2’ b1’ b0’
+ 1
a3 b3 a2 b2 a1 b1 a0 b0
A B A B A B A B
c4 c3 c2 c1 1
Cout Cin Cout Cin Cout Cin Cout Cin
S S S S
s3 s2 s1 s0
Lecture 13: 8
Four Bit Adder / Subtractor
a3 b3 a2 b2 a1 b1 a0 b0
0 1 0 1 0 1 0 1
A B A B A B A B
c4 c3 c2 c1
Cout Cin Cout Cin Cout Cin Cout Cin sub
S S S S
s3 s2 s1 s0
Lecture 13: 9
Adder Implementations
• Many different adder implementations exist, which differ
in speed and circuit complexity
Lecture 13: 10
Carry Lookahead Adder (CLA)
• Calculation of carry out of MSB is slow for large
RCAs
– Carry has to propagate from LSB to the MSB, which
forms the longest path (critical path)
Lecture 13: 11
Carry Generation and Propagation
01010010 11000110
+ 00010011 + 00101011
01100101 11110001
generated generated propagated generated
Lecture 13: 12
Carry Generation and Propagation
• Carry into ith position: ci
– Also the carry out from (i-1)th position
Lecture 13: 13
Carry Out Equations for 4-bit Adder
c 1 = G0 + P 0 • c 0 Gi = a i • b i
P i = ai + b i
c 2 = G1 + P 1 • c 1
= G1 + P 1 • G0 + P 1 • P 0 • c 0
c 3 = G2 + P 2 • c 2
= G2 + P 2 • G1 + P 2 • P 1 • G0 + P 2 • P 1 • P 0 • c 0
c 4 = G3 + P 3 • c 3
= G3 + P 3 • G2 + P 3 • P 2 • G1 + P 3 • P 2 • P 1 • G0 + P 3 • P 2 • P 1 • P 0 • c 0
Lecture 13: 14
Carry Out Logic for 4-bit Adder
Gi = a i • b i
P i = ai + b i
c 4 = G3 + P 3 • c 3
= G3 + P 3 • G2 + P 3 • P 2 • G1 + P 3 • P 2 • P 1 • G0 + P 3 • P 2 • P 1 • P 0 • c 0
= G 3 + P 3 • ( G 2 + P 2 • ( G 1 + P 1• G 0 ) ) + ( P 3 • P 2 • P 1 • P 0 ) • c 0
G3:0 – Carry generation P3:0 – Carry propagation through
from bits 3-0 bits 3-0
G3:0 G3
P3
G2
P2
G1
P1
G0
c4
P3:0 P3
P2
c0 P1
P0
Lecture 13: 15
32-bit CLA with 4-bit RCAs
a31:28 b31:28 a27:24 b27:24 a7:4 b7:4 a3:0 b3:0
cout (c32) 4-bit CLA c28 4-bit CLA c24 … 4-bit CLA c4 4-bit CLA cin (c0)
Block Block Block Block
Lecture 13: 16
32-bit CLA with 4-bit RCAs
a31:28 b31:28 a27:24 b27:24 a7:4 b7:4 a3:0 b3:0
cout (c32) 4-bit CLA c28 4-bit CLA c24 … 4-bit CLA c4 4-bit CLA cin (c0)
Block Block Block Block
c3 c2 c1 c0
FA FA FA FA
S3 S2 S1 S0
S7 S6 S5 S4 S3 S2 S1 S0
S 31 S 30 S 29 S 28
G 7:4 G7 G 3:0 G3
…
G 31:28 G 31
P7 P3
P3 G6 G2
G2 P2
P6
P2 G5 G1
G1 P1
P5
P 29 G4 G0
G 28
c8 c4
c 32 P7 P 3:0 P3
P 31 P 7:4 P2
P 31:28 P6
P 30 P5 c0 P1
P 29 c4 P4 P0
c 28 P 28
Lecture 13: 18
Longest Delay (Critical Path)
S7 S6 S5 S4 S3 S2 S1 S0
S 31 S 30 S 29 S 28
G 7:4 G7 G 3:0 G3
…
G 31:28 G 31
P7 P3
P3 G6 G2
G2 P2
P6
P2 G5 G1
G1 P1
P5
P 29 G4 G0
G 28
c8 c4
c 32 P7 P 3:0 P3
P 31 P 7:4 P2
P 31:28 P6
P 30 P5 c0 P1
P 29 c4 P4 P0
c 28 P 28
Lecture 13: 19
Our Microprocessor is Built to Compute
MUX
0
+2 Adder 1
sext({OFF,0})
MP
Fm … F0
DR RF DataA
Inst. RAM
SA M_address
Decoder
SB RW Data
DataB ALU
PC
MB SA Data_in 0
FS
0 RAM
SB 1 1
MD DR
RW D_in VCZN
SE
MW MB MW MD
IMM
Lecture 13: 20
What is an ALU?
• Arithmetic Logic Unit (ALU): Combinational
logic circuit that combines a variety of
operations into a single unit
Lecture 13: 21
A Simple 8-Bit ALU
8 8
B A
SI SO
CI ALU CO
O
OP
Y Z
3
Lecture 13: 22
ALU Operations, Inputs & Outputs
• Operations
– Addition and Subtraction
– Bitwise AND and OR
– Left Shift and Right Shift
• Inputs
– A, B, Carry In (CI)
– Shift In (SI)
– Code indicating operation to be performed (OP)
• Outputs
– Y, Carry Out (CO)
– Shift Out (SO)
– Flags regarding the result of the operation
• Overflow flag (O), Zero flag (Z)
Lecture 13: 23
Shift Operations
• Left Shift: shifts each bit left by 1 position
A7 A6 A5 A4 A3 A2 A1 A0 SI
SO=A7 A6 A5 A4 A3 A2 A1 A0 SI
SI A7 A6 A5 A4 A3 A2 A1 A0=SO
Lecture 13: 25
Example: ALU Operation Encodings
OP Name OP BSEL CI LOP SOP OSEL Operation
ADD 000 0 - - 00 Y = A + B + CI
SUB 001 1 - - 00 Y = A + B’ + 1
AND 011 - 0 - 01 Y = A AND B
OR 100 - 1 - 01 Y = A OR B
SHL 101 - - - 0 10 Y = A[6..0],SI
SHR 110 - - - 1 10 Y = SI,A[7..1]
PASS A 111 10 0 - - 00 Y = A
Adder
8 8 A 8
A Y
8 B CO CO
B 8 8 00 CI CI O O
8 8 01
8
Logical 00
0 10 8
A
8 Y 8 01 8 Y
B
LOP 10 8
Control Logic Shifter
2 8 NOR Z
BSEL A 8
3 Y
OP OP LOP SI SI
SO SO
SOP SOP
OSEL 2
Lecture 13: 26
Before Next Class
• H&H 7.1-7.3.1
Next Time
Memories
Lecture 13: 27