DD Vahid ch4
DD Vahid ch4
DD Vahid ch4
Introduction
Chapters 2 & 3: Introduced increasingly complex digital building blocks
Gates, multiplexors, decoders, basic registers, and controllers
4.1
Registers
b
4.2
x Combinational n1 logic n0 s1 s0
Can store data, very common in datapaths Basic register of Ch 3: Loaded every cycle
Useful for implementing FSM -- stores encoded state For other uses, may want to load only on certain cycles
clk
State register
load
clk
I3
I2
I1
I0 4-bit register
D Q
D Q
D Q
D Q
i s
i s n a
I3 I2 I1 I0 reg(4)
Q3 Q2 Q1 Q0
Q3 Q2 Q1 Q0
e
Basic register loads on every clock cycle How extend to only load on certain cycles?
Digital Design Copyright 2006 Frank Vahid
I2
1 0
I1
1 0
I0
1 0
I3
load
I2
I1
I0
D Q Q3
D Q Q2
D Q Q1
D Q3 Q Q0
(c)
I0
1 0
Q2
Q1
Q0
(a)
I3
I2
1 0
I1
1 0
I3
I2
1 0
I1
1 0
I0
1 0
load = 0
1 0
load = 1
1 0
D Q Q3
Digital Design Copyright 2006 Frank Vahid
D Q Q2
D
Q Q1
D Q Q0
D Q Q3
D Q Q2
D Q Q1
D Q Q0
(b)
This example will show how registers load simultaneously on clock cycles
Notice that all load inputs set to 1 in this example -- just for demonstration purposes
R0 Q3 Q2 Q1 Q0
ld I3
I2
I1
I0 R1
1 ld I3
I2
I1
I0 R2
Q3 Q2 Q1 Q0
Q3 Q2 Q1 Q0
(a)
given
1
a3..a0
2 0001 1010
1111
R 0 R 1 R 2
a3 a2 a1 a0 1 clk ld I3 I2 I1 I0
>1111
???? R 0
R0
Q3 Q2 Q1 Q0
(b)
???? R 1
1 ld I3 I2 I1 I0 1 ld I3 I2 I1 I0
???? R 2
???? R 1
???? R 2
1111 R 1
0000 R 2
0001 R 1
1110 R 2
1010 R 1
0101 R 2
1010 R 1
0101 R 2
R1
Q3 Q2 Q1 Q0
R2
Q3 Q2 Q1 Q0
0 0 1 1 0
Save 2 3 pounds Present weight b clk
load
I3 I2 I1 I0 Q3 Q2 Q1 Q0
0 0 1 1
a4 a3 a2 a1 a0
a4 a3 a2 a1 a0
b4 b3 b2 b1 b0 I4 Q4 I3 Q3 I3 Q3 I2 Q2 I2 Rb Q2 I1 Q1 I1 Q1 I0 Q0 I0 Q0 Rb
b4 b3 b2 b1 b0
I4 Q4 I3 Q3 I3 Q3 I2 Q2 I2 Rc Q2 I1 Q1 I1 Q1 I0 Q0 I0 Q0 Rc
c4 c3 c2 c1 c0
c4 c3 c2 c1 c0
t4 x4 t3 x3 t2 x2 t1 x1 t0
x0
Q4 I4 I4 Q4 I3 Q3 I3 Q3 I2 Q2 Ra Q2 I2 I1 Q1 I1 Q1 I0 Q0
I0 Q0
I4
Q4
I4
Q4
ld
Ra
ld
ld
TemperatureHistoryStorage
new line
TemperatureHistoryStorage
0001010
r e
8 d0 2 4 a0
u p m o
l a
i0
's r a c e h t m o
Ch2 example: Four simultaneous values from cars computer To reduce wires: Computer writes only 1 value at a time, loads into one of four registers
Was: 8+8+8+8 = 32 wires Now: 8 +2+1 = 11 wires
Digital Design Copyright 2006 Frank Vahid
0 1
d1 i0 i1 d2
8 load reg1
0001010
A 8
i1 load reg2 I i2 8 d 8
a1
load
d3
load reg3
M 8 i3 s1 s0 x y 9
8
b a e h t o r r s l p i d r o
8-bit 41
a y
load
(a)
10
R7
R6
R5
R4
R3
R2
R1
R0
D i2,i1,i0 e clk
11
Shift Register
Shift right
Move each bit one position right Shift in 0 to leftmost bit
1 1 0 1 0 0 1 1 0 Register contents before shift right
a
12
Shift Register
To allow register to either shift or retain, use 2x1 muxes
shr: 0 means retain, 1 shift shr_in: value to shift in
May be 0, or 1
Note: Can easily design shift register that shifts left instead
shr_in shr 1 0 2 1 D Q Q3 1 0
shr=1
1 0
1 0
1 0 2 1 D Q
10 D Q Q2 (b)
10 D Q Q1
1 0 D Q Q0
D Q Q2 (a)
D Q Q1
D Q Q0
Q3
shr_in shr Q3
Digital Design Copyright 2006 Frank Vahid
Q2 (c)
Q1
Q0
13
Rotate Register
1 1 0 1 Register contents before shift right Register contents after shift right
Rotate right: Like shift right, but leftmost bit comes from rightmost bit
1 1 1 0
14
Earlier example: 8 +2+1 = 11wires from cars computer to above-mirror displays four registers
Better than 32 wires, but 11 still a lot -want fewer for smaller wire bundles
wir es
C
d0
load
reg0
2 4 d1
i0 8
11
a0
load
reg1
A
8
8-bit 4 1
i1
i0 i1 d2
a1
load
reg2
I
i2 8
e load
d3
load
reg3
M 8
i3 s1 s0
Note: this line is 1 bit, rather than 8 bits like before x y c shr_in shr reg0 d0 T s1 s0 i0 2 4 8 shr_in 41 shr reg1 d1 A a0 i0 i1 8 i1 a1 shr_in d shr reg2 d2 8 I i2 e d3 shr_in shr reg3 8 M i3 8
shift
15
Multifunction Registers
Many registers have multiple functions
Load, shift, clear (load all 0s) And retain present value, of course
Functions:
s1 0 0 1 1
I0 0 3210 shr_in s1 s0 I3 I2 I1 I0
s0 0 1 0 1
Operation Maintain present value Parallel load Shift right (unused - let's load 0s)
I2 0 3210
I1 0 3210
D Q Q2 (a)
D Q Q1
D Q Q0
Q3 Q2 Q1 Q0
(b)
16
Multifunction Registers
s1 0 0 1 1 s0 0 1 0 1 Operation Maintain present value Parallel load Shift right Shift left
I3 shr_in
I2
I1
I0 shl_in
3210
3210
3210
I3
I2
I1
I0
D Q Q3
Digital Design Copyright 2006 Frank Vahid
D Q Q2 (a)
D Q Q1
D Q Q0
Q3 Q2 Q1 Q0
(b)
17
I3 shr_in s1 s0 I3
I2 I2
I1 I1
I0 I0 shl_in
shl_in Q3 Q2 Q1 Q0 Q3 Q2 Q1 Q0
18
Put highest priority control input on left to make reduced table simple
Inputs shr shl ld 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 Outputs s1 s0 0 1 1 1 0 0 0 0 0 1 0 0 1 1 1 1 Note Operation Maintain value Shift left Shift right Shift right Parallel load Parallel load Parallel load Parallel load ld 0 0 0 1 shr shl 0 0 1 X 0 1 X X Ope ration Maintain value Shi t left f Shift right Parallel load
19
20
5 operations: above, plus maintain present value (dont forget this one!) --> Use 8x1 mux
1 0
s2 s1 s0
In from Qn-1
7 6 5 4 3 2 1 0 D Q Qn
Step 2: Create mux operation table Step 3: Connect mux inputs Step 4: Map control lines
s2 = clr*set s1 = clr*set*ld*shl + clr s0 = clr*set*ld + clr
Digital Design Copyright 2006 Frank Vahid
clr 0
0 0
Inputs set ld 0 0
0 0 0 1
shl 0
1 X
Outputs s2 s1 s0 0 0 0
0 0 1 0 0 1
0 1
a
1 X
X X
X X
1 0
0 1
0 1
21
shl_in Q3 Q2 Q1 Q0 Q3 Q2 Q1 Q0
clr 0
0 0
Inputs set ld 0 0
0 0 0 1
shl 0
1 X
Outputs s2 s1 s0 0 0 0
0 0 1 0 0 1
0 1
1 X
X X
X X
1 0
0 1
0 1
22
Adders
Adds two N-bit binary numbers
2-bit adder: adds two 2-bit numbers, outputs 3-bit result e.g., 01 + 11 = 100 (1 + 3 = 4)
a1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 Inputs a0 b1 0 0 0 0 0 1 0 1 1 0 1 0 1 1 1 1 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 b0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 c 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 1
4.3
Can design using combinational design process of Ch 2, but doesnt work well for reasonable-size N
Why not?
Outputs s1 s0 0 0 0 1 1 0 1 1 0 1 1 0 1 1 0 0 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 1
23
4.3
8-bit adder: 2(8+8) = 65,536 rows 16-bit adder: 2(16+16) = ~4 billion rows 32-bit adder: ...
a1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 10000 8000
Inputs a0 b1 0 0 0 0 0 1 0 1 1 0 1 0 1 1 1 1 0 0 0 0 0 1 0 1 1 0 1 0 1 1 1 1
b0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
c 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 1
Outputs s1 s0 0 0 0 1 1 0 1 1 0 1 1 0 1 1 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 1 1 0
s r o
A: 1000 transistors for N=5, doubles for each increase of N. So transistors = 1000*2(N-5). Thus, for N=16, transistors = 1000*2(16-5) = 1000*2048 = 2,048,000. Way too many!
Digital Design Copyright 2006 Frank Vahid
s i n a
24
A: B: +
1 1 1 1 0 1 1 0
0 1
1 0 1
1 0 1 0 1
25
A: B:
1 1 1 1 + 0 1 1 0
1 0 1 0 1 1 1 1 0 b a ci co s 1 0 1 b a ci co s 1 0 1 1 b a ci co s 0 1 0 b a co s 1 SUM
A: 1
B:
Full-adders
Half-adder
26
Half-Adder
1 1 1 1 b a ci co s 1 0 1 1 b a ci co s 0 1 0 b a co s 1 SUM
Half-adder: Adds 2 bits, generates sum and carry Design using combinational design process from Ch 2
Inputs b a 0 0 1 0 0 1 1 1
A: 1
B: 0 b a ci co s
Outputs co s 0 0 1 0 1 0 0 1
Half-adder
co s co s
27
Full-Adder
1 1 1 1 b a ci co s 1 0 1 1 b a ci co s 0 1 0 b a co s 1 SUM
Full-adder: Adds 3 bits, generates sum and carry Design using combinational design process from Ch 2
A: 1
B: 0 b a ci co s
Step 1: Capture the function Step 2: Convert to equations Step 3: Create the circuit Inputs Outputs
a b ci a 0 0 0 0 1 1 1 1 b 0 0 1 1 0 0 1 1 ci 0 1 0 1 0 1 0 1 co 0 0 0 1 0 1 1 1 s 0 1 1 0 1 0 0 1
co = abc + abc + abc + abc co = abc +abc +abc +abc +abc +abc co = (a+a)bc + (b+b)ac + (c+c)ab co = bc + ac + ab s = abc + abc + abc + abc s = a(bc + bc) + a(bc + bc) s = a(b xor c) + a(b xor c) s = a xor b xor c
Full adder
co s
28
Carry-Ripple Adder
Using half-adder and full-adders, we can build adder that adds like we would by hand Called a carry-ripple adder
4-bit adder shown: Adds two 4-bit numbers, generates 5-bit output
5-bit output can be considered 4-bit sum plus 1-bit carry out
a3 a2 a1 a0
b3 b2 b1 b0
4-bit adder s3 s2 s1 s0
co
s3
s2 (a)
s1
s0 (b)
29
Carry-Ripple Adder
Using full-adder instead of half-adder for first bit, we can include a carry in bit in the addition
Will be useful later when we connect smaller adders to form bigger adders
a3 b3 a b ci F A co s co a2 b2 a b ci F A s co a1 b1 a b ci F A s co a0 b0 ci a b ci F A s co
a3 a2 a1 a0
b3 b2 b1 b0 ci
4-bit adder s3 s2 s1 s0
co
s3
s2 (a)
s1
s0 (b)
30
a b ci F A s 0 1 1
000 a b ci F A co 0
Digital Design Copyright 2006 Frank Vahid
0111+0001
(answer should be 01000)
a b ci F A co s 0 1 co0
s 0
Wrong answer -- something wrong? No -- just need more time for carry to ripple through the chain of full adders.
31
0111+0001
(answer should be 01000)
a b ci F A co 1 s 0
a b ci F A co 1 s
a
0 0
0 00 1 a b ci F A co 0 s 1
32
Cascading Adders
a7a6a5a4 a3a2a1a0
b7b6b5b4 b3b2b1b0 ci
a3a2a1a0 a3a2a1a0
(b)
33
a7..a0
b7..b0 ci 0
a
CALC LEDs
Digital Design Copyright 2006 Frank Vahid
34
b7..b0 ci 0
s7..s0
ld
35
01000010
a7..a0
ci
1 clk
Digital Design Copyright 2006 Frank Vahid
ld
Weight Adjuster
to display
36
Shifters
Shifting (e.g., left shifting 0011 yields 0110) useful for:
Manipulating bits Converting serial data to parallel (remember earlier above-mirror display example with shift registers) Shift left once is same as multiplying by 2 (0011 (3) becomes 0110 (6))
Why? Essentially appending a 0 -- Note that multiplying decimal number by 10 accomplished just be appending 0, i.e., by shifting left (55 becomes 550)
i3 i2 i1 i0
4.4
shL shR
<<1
q3
q2
q1
q0 q3 q2 q1 q0
q3
q2
q1
q0
Symbol
Left shifter
00001100 (12)
*2
0 (shift in 0) 00100000 (32) 8
a
00011000 (24)
8-bit adder
00111000 (56)
Digital Design Copyright 2006 Frank Vahid
8 F
38
divide by 4
0001010 (10)
ld Ravg Tavg
39
Barrel Shifter
A shifter that can shift by any amount
4-bit barrel left shift can shift left by 0, 1, 2, or 3 positions 8-bit barrel left shifter can shift left by 0, 1, 2, 3, 4, 5, 6, or 7 positions
(Shifting an 8-bit number by 8 positions is pointless -- you just lose all the bits)
i3 01
i2 01
i1 01
i0 in 01 sh
q3
q2
q1
q0
Shift by 1 shifter uses 2x1 muxes. 8x1 mux solution for 8-bit barrel shifter: too many wires.
Q: xyz=??? to shift by 5?
1
x sh
00000110
in 0
a
<<4 8
0
y sh
01100000 (by 4)
in 0
<<2 8
1
z sh
01100000
in 0
40
<<1 Q
11000000 (by 1)
Comparators
N-bit equality comparator: Outputs 1 if two N-bit numbers are equal
4-bit equality comparator with inputs A and B
a3 must equal b3, a2 = b2, a1 = b1, a0 = b0
Two bits are equal if both 1, or both 0 eq = (a3b3 + a3b3) * (a2b2 + a2b2) * (a1b1 + a1b1) * (a0b0 + a0b0)
4.5
Recall that XNOR outputs 1 if its two input bits are the same
eq = (a3 xnor b3) * (a2 xnor b2) * (a1 xnor b1) * (a0 xnor b0)
a3 b3 a2 b2 a1 b1 a0 b0
0110 = 0111 ?
0 0
1 1
1 1
0 1
a3 a2 a1 a0 b3 b2 b1 b0
a
0
Digital Design Copyright 2006 Frank Vahid
eq (a)
41
Magnitude Comparator
N-bit magnitude comparator: A=1011 B=1001 Indicates whether A>B, A=B, or 1011 1001 Equal A<B, for its two N-bit inputs A and B How design? Consider how compare 1011 1001 Equal
by hand. First compare a3 and b3. If equal, compare a2 and b2. And so on. Stop if comparison not equal -whichevers bit is 1 is greater. If never see unequal bit pair, A=B.
1011
1001 Unequal
So A > B
42
Magnitude Comparator
By-hand example leads to idea for design
Start at left, compare each bit pair, pass results to the right Each bit pair called a stage Each stage has 3 inputs indicating results of higher stage, passes results to lower stage
a3 b3 a Igt Ieq Ilt b a2 b2 a b a1 b1 a b a0 b0 a b AgtB AeqB AltB
0 1 0
a3a2a1a0
b3b2b1b0
Magnitude Comparator
a3 b3 a Igt Ieq Ilt b a2 b2 a b a1 b1 a b a0 b0 a b AgtB AeqB AltB
Each stage:
out_gt = in_gt + (in_eq * a * b)
A>B (so far) if already determined in higher stage, or if higher stages equal but in this stage a=1 and b=0
Simple circuit inside each stage, just a few gates (not shown)
Digital Design Copyright 2006 Frank Vahid
44
Magnitude Comparator
How does it work?
1011 = 1001 ?
1 = 1 a3 b3 a b 0 0 a2 b2 a b 1 0 a1 b1 a b 1 1 a0 b0 a b AgtB AeqB AltB
0 0 Igt in_gt out_gt in_gt out_gt 1 1 Ieq in_eq out_eq in_eq out_eq 0 0 in_lt out_lt in_lt out_lt Ilt S tage3 S tage2 (a) 0 = 0 a2 b2 a b
1 1 a3 b3 a b 0 Igt in_gt out_gt 1 Ieq in_eq out_eq 0 in_lt out_lt Ilt S tage3
1 0 a1 b1
a b 0 in_gt out_gt in_gt out_gt 1 in_eq out_eq in_eq out_eq 0 in_lt out_lt in_lt out_lt S tage2 (b) S tage1
45
Magnitude Comparator
1011 = 1001 ?
1 1 0 0 1 > 0 a1 b1 1 a0 1 b0 a3 b3 a2 b2
b out_gt out_lt
a in_gt in_lt
b out_gt out_lt
a in_gt in_lt
b out_gt out_lt 1 0 0
a in_gt in_lt
in_eq out_eq
in_eq out_eq
in_eq out_eq
in_eq out_eq
AeqB
S tage3
S tage2 (c)
S tage1
S tage0
1 a1 0 b1 1 a0 1 b0
a3 b3
a2 b2
b out_gt out_lt
a in_gt in_lt
b out_gt out_lt
a in_gt in_lt
b out_gt out_lt
a in_gt in_lt
Final answer appears on the right Takes time for answer to ripple from left to right Thus called carry-ripple style after the carry-ripple adder
Even though theres no carry involved
46
in_eq out_eq
in_eq out_eq
in_eq out_eq
in_eq out_eq
S tage2 (d)
S tage1
S tage0
01111111
B 8 8 AgtB AeqB AltB 8 8 I0 A Min C 8 (b) 8 8 B
0 1 0
1 0 0
I1
(a)
01111111
Digital Design Copyright 2006 Frank Vahid
47
Counters
N-bit up-counter: N-bit register that can increment (add 1) to its own value on each clock cycle
0000, 0001, 0010, 0011, ...., 1110, 1111, 0000 Note how count rolls over from 1111 to 0000
Terminal (last) count, tc, equals1 during value just before rollover
cnt ld 4-bit register
4.6
0 1
cnt
4-bit up-counter tc C 4
0 0 1
0101 0100 0011 0010 0001 0000 0001 0000 1111 1110 ...
4-bit up-counter
Internal design
Register, incrementer, and N-input AND gate to detect terminal count
tc
Digital Design Copyright 2006 Frank Vahid
4 4 C
4 +1 4
48
Incrementer
Counter design used incrementer Incrementer design
Could use carry-ripple adder with B input set to 00...001
But when adding 00...001 to another number, the leading 0s obviously dont need to be considered -- so just two bits being added per column
Use half-adders (adds two bits) rather than full-adders (adds three bits)
a3 a2 a b HA co s s2 (a) a1 a b HA co s s1 a0 1 a3 a2 a1 a0 +1 co s3 s2 s1 s0 (b)
49
carries:
a b HA co s co s3
a b HA co s s0
Incrementer
Can build faster incrementer using combinational logic design process
Capture truth table Derive equation for each output
c0 = a3a2a1a0 ... s0 = a0
Inputs a3 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 a2 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 a1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 a0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 c0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 Outputs s3 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 s2 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 s1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 s0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
Results in small and fast circuit Note: works for small N -- larger N leads to exponential growth, like for N-bit adder
50
mode clk
cnt
x y
51
cnt
52
Down-Counter
4-bit down-counter
1111, 1110, 1101, 1100, , 0011, 0010, 0001, 0000, 1111, Terminal count is 0000
Use NOR gate to detect
4-bit down-counter cnt ld 4-bit register
4 4 C
4 1 4
53
Up/Down-Counter
Can count either up or down
Includes both incrementer and decrementer Use dir input to select, using 2x1: dir=0 means up Likewise, dir selects appropriate terminal count value
dir 4-bit up/down counter
4-bit 2 x 1 0 4
clr cnt
clr ld
4-bit register
4 4
4 1 4
4 +1 4
1 2x 1 0 tc
Digital Design Copyright 2006 Frank Vahid
54
0 0 1 0 0 1 0
i2 i1 i0
d7 d6 d5 d4 d3 d2 d1 d0
a
lights
55
cnt
ld 4-bit register
4 4 tc C
4 +1
56
1000
4
4-bit down-counter
tc 4 C
clk
9 counts
57
Counter Example:
New Years Eve Countdown Display
Chapter 2 example previously used microprocessor to counter from 59 down to 0 in binary Can use 8-bit (or 7- or 6-bit) down-counter instead, initially loaded with 59
59 8 L ld reset c0 c1 c2 c3 c4 c5 c6 c7 i0 i1 i2 i3 i4 i5 d0 d1 d2 d3 0 1 2 3 Happy New Year
58 59
fireworks
58
Counter Example:
1 Hz Pulse Generator from 60 Hz Clock
U.S. electricity standard uses 60 Hz signal
Device may convert that to 1 Hz signal to count seconds
1 osc (60 Hz) clr cnt 6-bit up counter tc p C
(1 Hz)
59
Timer
A type of counter used to measure time
If we know the counters clock frequency and the count, we know the time thats been counted
60
4.7
61
62
b1
pp2
pp1
0
0 + (5-bit)
b2
pp3
00 A + (6-bit) B
b3
pp4
0 00 + (7-bit)
Block symbol
p7..p0
63
Subtractor
Can build subtractor as we built carry-ripple adder
Mimic subtraction by hand Compute borrows from columns on left
Use full-subtractor component:
wi is borrow by column on right, wo borrow from column on left
1stcolumn 0 1 0 1 10 - 0 1 1 1 1 a3 b3 a b wi FS wo s wo s3
Digital Design Copyright 2006 Frank Vahid
4.8
2nd column 0 1 10 1 10 1 0 - 0 1 1 1 1 1
3rd column 0 1 1 10 1 0 - 0 1 0 1 1 1 1
4th column 0 1 0 1 0 - 0 0 1 0 1 1 1 1
a2 b2 a b wi FS wo s s2
a1 b1 a b wi FS wo s s1
(b)
(c)
64
A B wi 8-bit subtractor wo 8 S
2x1 8
65
Subtractor Example:
Color Space Converter RGB to CMYK
Color
Often represented as weights of three colors: red, green, and blue (RGB)
Perhaps 8 bits each, so specific color is 24 bits
White: R=11111111, G=11111111, B=11111111 Black: R=00000000, G=00000000, B=00000000 Other colors: values in between, e.g., R=00111111, G=00000000, B=00001111 would be a reddish purple
Good for computer monitors, which mix red, green, and blue lights to form all colors
Digital Design Copyright 2006 Frank Vahid
Subtractor Example:
Color Space Converter RGB to CMYK
Printers must quickly convert RGB to CMY
C=255-R, M=255-G, Y=255-B Use subtractors as shown
Y M C o t
R 255 8 8 255 8
G 8 255
B 8
B G R
8 8 M Y
67
Subtractor Example:
Color Space Converter RGB to CMYK
Try to save colored inks
Expensive Imperfect mixing C, M, Y doesnt yield good-looking black
Solution: Factor out the black or gray from the color, print that part using black ink
e.g., CMY of (250,200,200)= (200,200,200) + (50,0,0).
(200,200,200) is a dark gray use black ink
Digital Design Copyright 2006 Frank Vahid
68
Subtractor Example:
Color Space Converter RGB to CMYK
Call black part K
(200,200,200): K=200
(Letter B already used for blue)
M C o
B G
8 M2
8 Y2
8 K 8
69
Signed-magnitude
Use leftmost bit for sign bit
So -5 would be:
1101 using four bits 10000101 using eight bits
70
Tens Complement
1 9 8 7 6 5 4 3 2 1
2 3 4 5 6 7 8 9
71
Tens Complement
Nice feature of tens complement
Instead of subtracting a number, adding its complement results in answer exactly 10 too much So just drop the 1 results in subtracting using addition only
complements 1 2 3 4 5 6 7 8 9 0
Digital Design Copyright 2006 Frank Vahid
9 8 7 6 5 4 3 2 1 10 74=3 3 0 4 4 7
10 6
10 +6 13 13 3
20
7+6=13
Adding the complement results in an answer exactly 10 too much dropping the tens column gives the right answer.
72
True but in binary, it turns out that the twos complement can be computed easily
Twos complement of 011 is 101, because 011 + 101 is 1000 Could compute complement of 011 as 1000 011 = 101 Easier method: Just invert all the bits, and add 1 The complement of 011 is 100+1 = 101 -- it works!
a
73
A Adder
B cin
74
Adder/Subtractor
Adder/subtractor: control input determines whether add or subtract
Can use 2x1 mux sub input passes either B or inverted B Alternatively, can use XOR gates if sub input is 0, Bs bits pass through; if sub input is 1, XORs invert Bs bits
75
e clk
DIP swi tches
1 0 clk
f e
76
Overflow
Sometimes result cant be represented with given number of bits
Either too large magnitude of positive or negative e.g., 4-bit twos complement addition of 0111+0001 (7+1=8). But 4bit twos complement cant represent number >7
0111+0001 = 1000 WRONG answer, 1000 in twos complement is -8, not +8
Adder/subtractor should indicate when overflow has occurred, so result can be discarded
77
Simple circuit
overflow = a3b3s3 + a3b3s3 Include overflow output bit on adder/subtractor
sign bits 0 1 1 1 +0 0 0 1 1 0 0 0 overflow (a)
Digital Design Copyright 2006 Frank Vahid
1 1 1 1 +1 0 0 0 0 1 1 1 overflow (b)
1 0 0 0 +0 1 1 1 1 1 1 1 no overflow (c)
If the numbers sign bits have the same value, which differs from the results sign bit, overflow has occurred.
78
1 1 1 0 1 1 1 +0 0 0 1 0 1 0 0 0 overflow (a)
0 0 0 1 1 1 1 +1 0 0 0 10 1 1 1 overflow (b)
0 0 0 1 0 0 0 +0 1 1 1 01 1 1 1 no overflow (c)
If the carry into the sign bit column differs from the carry out of that column, overflow has occurred.
79
4.9
80
+ 8
+1 8 8 8
AND
OR
XOR NOT
8 8
8 A lot of wires
CALC 8
LEDs
81
ALU
More efficient design uses ALU
ALU design not just separate components multiplexed (same problem as previous slide!), Instead, ALU design uses single adder, plus logic in front of adders A and B inputs
Logic in front is called an arithmetic-logic extender
Extender modifies the A and B inputs such that desired operation will appear at output of the adder
82
xyz=000: Want S=A+B just pass a to ia, b to ib, and set cin=0 xyz=001: Want S=A-B pass a to ia, b to ib, and set cin=1 xyz=010: Want S=A+1 pass a to ia, set ib=0, and set cin=1 xyz=011: Want S=A pass a to ia, set ib=0, and set cin=0 xyz=1000: Want S=A AND B set ia=a*b, b=0, and cin=0 others: likewise Based on above, create logic for ia(x,y,z,a,b) and ib(x,y,z,a,b) for each abext, and create logic for cin(x,y,z), to complete design of the AL-extender component
Digital Design Copyright 2006 Frank Vahid
83
LEDs
Digital Design Copyright 2006 Frank Vahid
84
Register Files
MxN register file component provides efficient access to M Nbit-wide registers
s
?
4.10
r e
32 C
r e t
u p m o
8 d0d0 4 16 4 2
reg0
huge mux 32 8
l p i d r o s
b a e h t o
u p m o
i m
r a c e h t m o
If we have many registers but only need access one or two at a time, a register file is more efficient Ex: Above-mirror display (earlier example), but this time having 16 32-bit registers
r F
l a
b a e h t o
i m
l p i d r o s
's r a c e h t m o
l a
a0
d1 i0 d2
i3-i0i1 a1
load reg2
I 8
dd
328
DD
d15 e
d3
M 32 8
load
load
85
Register File
Instead, want component that has one data input and one data output, and allows us to specify which internal register to write and which to read
32 W_data 4 W_addr W_en 1632 register file R_data R_addr R_en 4
a
32
86
32 2
87
OLD design
a
d0
From the car s central computer
load reg0
32
C 32 much too W_data fanout 4 W_addr W_en 16 32 register file
huge mux i0
To the abovemirror display
D 32 32-bit R_data 16x 1 4 R_addr R_en 1
4 16 4 i3-i0
WA load
32 RA
congestion e
d15
load reg15
load
i15
32 s3-s0
88
Chapter Summary
Need datapath components to store and operate on multibit data
Also known as register-transfer-level (RTL) components
Components introduced
Registers Shifters Adders Comparators Counters Multipliers Subtractors Arithmetic-Logic Units Register Files
Next, well combine knowledge of combinational logic design, sequential logic design, and datapath components, to build digital circuits that can perform general and powerful computations
Digital Design Copyright 2006 Frank Vahid
89