ALU Desing
ALU Desing
ALU Desing
Homework #3 Assigned Due Mar 4 Project: form groups of 3 (preferred) by Mar 6, I will assign after that Project Specifications on Web, Due April 17 (written document and demonstration) Building the building blocks Outline Review Digital building blocks An Arithmetic Logic Unit (ALU) Reading Appendix C, Chapter 3
Alvin R. Lebeck
CPS 104
b 0 0 1 1 0 1 1
c 0 1 0 1 0 0 1
f 1f 2 0 1 1 1 1 0 0 0 1 0 0 1 1 1
4
Alvin R. Lebeck
CPS 104
CPS 104
B
0 0 1 1 0 0 1 1
C
0 1 0 1 0 1 0 1
F
0 1 0 1 0 0 1 1
NOT(a)
a b
XOR(a,b)
a b
NAND(a,b)
a b
NOR(a,b)
a b
XNOR(a,b)
Alvin R. Lebeck
CPS 104
Alvin R. Lebeck
CPS 104
Parity Example
The parity code of a binary word counts the number of ones in a word. If there are an even number of ones the parity code is 0, if there are an odd number of ones the parity code is 1. For example, the parity of 0101 is 0, and the parity of 1101 is 1. Construct the truth table for a function that computes the parity of a four-bit word. Implement this function using AND, OR and NOT gates. (Note there are no constraints on the number of gate inputs.)
F = ~a*b + ~b*a
a 0 0 1 1
b 0 1 0 1
XOR(a,b) 0 1 1 0
a F
Alvin R. Lebeck
CPS 104
Alvin R. Lebeck
CPS 104
I1 I0 Q0 Q1 Q2 Q3 0 0 0 1 1 0 1 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
a b s
B
MUX(A, B, S) = (A * S) + (B * ~S)
Alvin R. Lebeck
CPS 104
Alvin R. Lebeck
CPS 104
10
a b y c d
3 2
c d
0 1 0
s0
s1
S
Alvin R. Lebeck
CPS 104
11
Alvin R. Lebeck
CPS 104
12
Alvin R. Lebeck
CPS 104
13
Alvin R. Lebeck
CPS 104
14
S3 Cout
Full Adder
S2
Full Adder
S1
Full Adder
S0
Full Adder
a
Cin 0
3 2 1
F 0 1 2 3 Q a+b NOT b a OR b a AND b
a3 b3
a2 b2
a1
b1
a0
b0
Adder
0 2
Cout F
Alvin R. Lebeck CPS 104 15 Alvin R. Lebeck CPS 104 16
Subtraction
How do we perform integer subtraction? What is the HW?
ALU Slice
Cin
A 0 1 F 0 0 1 2 3 Q a+b a-b NOT b a OR b a AND b
a b
3 2 1
1 0
Adder
0 2
~Add/Sub
Cout F
Alvin R. Lebeck CPS 104 17 Alvin R. Lebeck CPS 104 18
Overflow
Example1: 0100000 01101012 (= 5310) +01010102 (= 4210) 10111112 (=-3310) Example3: 1100000 01101012 (= 5310) +11010102 (=-2210) 00111112 (= 3110)
Alvin R. Lebeck
Example2: 1000000 10101012 (=-4310) +10010102 (=-5410) 00111112 (= 3110) Example4: 0000000 00101012 (= 2110) +01010102 (= 4210) 01111112 (= 6310)
CPS 104 19 Alvin R. Lebeck
S3 Cout
Full Adder
S2
Full Adder
S1
Full Adder
S0
Full Adder
Cin 0
a3 b3
a2 b2
a1
b1
a0
b0
CPS 104
20
The ALU
Overow = Zero
Abstraction: The ALU General structure Two operand inputs Control inputs
Q1 Q0
ALU control
Input A ALU
ALU Operation
Qn-1
Qn-2
ALU Slice
ALU Slice
ALU Slice
ALU Slice
Input B
Carry Out
an-1 bn-1
an-2 bn-2
a1
b1
a0
b0
Alvin R. Lebeck
CPS 104
21
Alvin R. Lebeck
CPS 104
22
Shifter
Alvin R. Lebeck
CPS 104
23
Alvin R. Lebeck
CPS 104
24
Memory Elements
All the circuit we looked at so far are combinational circuits: the output is a Boolean function of the inputs. We need circuits that can remember values. (registers) The output of the circuit is a function of the input AND a stored value (state) . Circuits with memory are called sequential circuits.
Alvin R. Lebeck
CPS 104
25
Alvin R. Lebeck
CPS 104
26
Set-Reset Latch
R Q R 0 1
R 0 0 1 1
S 0 1 0 1
Q Q 1 0 -
0 0
1 0
R 0 0 1 1
S 0 1 0 1
Q Q 1 0 -
Alvin R. Lebeck
CPS 104
27
Alvin R. Lebeck
CPS 104
28
0 0
Q Time
1 1
Data Time D E Q
1 0 1 0 1 0
S R Q
1 0 1 0 1 0
Alvin R. Lebeck
CPS 104
29
Alvin R. Lebeck
CPS 104
30
D Flip-Flop
D D E C Clock
On On D latch
D Flip-Flop Timing
Q Q D D D Q1 E
latch
D E
D latch
Q Q
D D Q E
latch
Q Q
Time
D Q1
1 0 0 1 0 1 1 0
C the output of the first stage is transferred to the second (output), and the first stage is stable.
Alvin R. Lebeck
CPS 104
31
Alvin R. Lebeck
CPS 104
32
Tri-State Driver
The
Bus Connections
The Bus: Many to many connections. Mutual exclusion: At most one Enable is on!
Tri-State driver is like a (one directional) switch: When the Enable is on (E=1) it transfers the input to the output. When the Enable is off (E=0) it disconnects the output.
E D Q
D 0 1 -
E 1 1 0
Q 0 1 Z
Z :- High Impedance
E
Alvin R. Lebeck
CPS 104
33
Alvin R. Lebeck
CPS 104
34
D latch
Q
D latch
Q
D latch
Q
RE
WE
RE
WE
RE
WE
RE
Q
Complement Q
Bus-A One can source and sink from any cell on the bus by activating the right controls (WE and RE).
DinEnable OutA OutB
Stores one bit of a register Can Read onto Bus-A & Bus-B and Write fromBus-C Simultaneously
Alvin R. Lebeck CPS 104 35 Alvin R. Lebeck CPS 104 36
EC
EA
EB
Bus-C Bus-B
Register address: 01
Bit-1
DEnable
Bus-A Bus-C Bus-B
Bit-0
Bus-A
B0 B1 EB C0 C1 EC
Alvin R. Lebeck
CPS 104
37
Alvin R. Lebeck
CPS 104
38
Summary
Given Boolean function, generate a circuit that realize the function. Constructed circuits that can add and subtract. The ALU: a circuit that can add, subtract, detect overflow, compare, and do bit-wise operations (AND, OR, NOT) Shifter Memory Elements: SR-Latch, D Latch, D Flip-Flop Tri-state drivers & Bus Communication Register Files Control Signals modify what circuit does with inputs
ALU, Shift, Register Read/Write
Reg-2
One-bit Cell
Reg-1
One-bit Cell
Reg-0
One-bit Cell
A3 B3 C3 A2 B2 C2 A1 B1 C1 A0 B0 C0
One-bit Cell
One-bit Cell
One-bit Cell
One-bit Cell
One-bit Cell
One-bit Cell
One-bit Cell
One-bit Cell
One-bit Cell
One-bit Cell
One-bit Cell
One-bit Cell
Alvin R. Lebeck
CPS 104
39
Alvin R. Lebeck
CPS 104
40