Chapter 2. Hardware Design Issues
Chapter 2. Hardware Design Issues
Combinational Logic
Sequential Logic
Custom Single-Purpose Processor Design
Optimizing Custom Single-Purpose Processors
1
Chapter 2 – Hardware Design Issues
CMOS Transistors
A transistor, which acts as a simple on/off switch, is the basic electrical component in digital system.
More abstract components, logic gates, are formed with the combinations of transistors. In
Complementary Metal Oxide Semiconductor (CMOS), the gate voltage controls the flow of current
from source to drain. The nMOS conducts when gate is at high voltage (5v) whereas pMOS conducts
when gate is at low voltage (0v). The symbol for nMOS and pMOS is shown in the figure 2.1.
Source Source
Gate Gate
Drain Drain
Figure 2.1: nMOS and pMOS transistors
Different gates and boolean functions can be realized using nMOS and pMOS.
A. Inverter: When x = 0, transistor T1 conducts but T2 does not. So, output is logic 1. And when x =
1, T2 conducts but T1 does not.
1 1
1 x T1 x y
T1 T2
T1
y T2 F = (xy)’
x F = x’ F = (x+y)’
x T3
T2
x T3 T4 y y T4
0
0 0
Figure 2.2: Inverter, NOR and NAND gate using nMOS and pMOS
2
Chapter 2 – Hardware Design Issues
B. NOR Gate
When x = 0 and y = 0, then T1 and T2 conduct but T3 and T4 don’t. So, F is connected to Vcc.
When x = 1 and y = 0, then T2 and T3 conduct but T1 and T4 don’t. So, F is connected to ground.
When x = 0 and y = 1, then T1 and T4 conduct but T2 and T3 don’t. So, F is connected to ground.
When x = 1 and y = 1, then T3 and T4 conduct but T1 and T2 don’t. So, F is connected to ground.
When atleast one of the two inputs is high then the output is connected to ground. And when both
inputs are low then the output is connected to Vcc.
C. NAND Gate
When x = 0 and y = 0, then T1 and T2 conduct but T3 and T4 don’t. So, F is connected to Vcc.
When x = 1 and y = 0, then T2 and T3 conduct but T1 and T4 don’t. So, F is connected to Vcc.
When x = 0 and y = 1, then T1 and T4 conduct but T2 and T3 don’t. So, F is connected to Vcc.
When x = 1 and y = 1, then T3 and T4 conduct but T1 and T2 don’t. So, F is connected to ground.
When atleast one out of two inputs is low then the output is connected to Vcc. And when both inputs
are high then the output is connected to ground.
3
Chapter 2 – Hardware Design Issues
value on each column of the output. Rows of the inputs are used to derive the equation
corresponding to the high output of the column. And the equation must be further
minimized.
Another way to derive minimized equation directly is by using k-map. It is always better to
use k-map unless the design is too simple (when the output column consists of only one
high value).
The final equation is translated to an equivalent circuit diagram using logic gates.
Truth Table
K-Map
a b c y z y bc
a 00 01 11 10
0 0 0 0 0
0 0 0 0 1
0
0 0 1 0 1 1 0 1 1 1
0
0 1 0 0 1 y = ac + bc’
0
0 1 1 1 0
0 Combinational Circuit
1 0 0 0 0
0 a
1 0 1 1 1 b
c y
0
1 1 0 1 1
0
1 1 1 1 1
0
Figure 2.3: Truth table, K-map, and combinational circuit for bank alarm system
4
Chapter 2 – Hardware Design Issues
I(m-1) I1 I0 I(logn - 1) I1 I0 X Y
n n n
S0
S1 n - bit
Log(n) x n n – bit
mx1 Decoder Adder
MUX
S(logm) n
n Carry Sum
Op O(n - 1) O1 O0
X Y X Y
n n n n
n bit m S0
n-bit
Comparator function S1
ALU
S(logm)
n
Less Equal Greater
Op
Figure 2.4: Few commonly used RT-Level Combinational Components
A multiplexer allows only one of its data inputs to pass through to the output. For m x 1
multiplexer there are m data inputs and one data output with log2m select lines. The value of
select line determines which input data to pass through to the output. It can be used for parallel
to serial conversion.
A decoder allows exactly one of the output lines to be high at a given time for a particular input.
For n input lines there will be 2n output lines. A decoder can be used for coding the addressing
lines in the memory. It can be used to convert binary to a suitable form.
An adder is used to add two n – bit inputs producing an n-bit sum along with a carry of 1 bit.
A comparator allows to compare two n-bit binary inputs, generating the corresponding output
based on whether one input is less than, equal to, or greater than another input.
An arithmetic-logic unit (ALU) performs variety of arithmetic and logic functions on its n – bit
inputs. The select line is used to select which function is to be carried out. If there are 2m
functions that can be done by ALU then there must be at least m select lines.
A shifter is another example which is used to shift the bits of the input right or left. It can be
used as a divider or multiplier. For example shifting 0110 (6) to the right would give 0011 (3).
5
Chapter 2 – Hardware Design Issues
A flip flop stores a single bit. The different types of flip flops are listed below.
D-flip flop: It has two inputs D and clock, when clock is high, value of D is stored in flip flop and
same will be the value of the output Q. When clock is low, previously stored bit is maintained
ignoring the value of input D.
SR flip flop: It has three inputs S (set), R (reset) and clock. When clock is low, the previously
stored bit is maintained ignoring the values of input at S and R. When clock is high, the output
varies with inputs S and R. If S is high, the output Q will be high and high bit (1) will be stored by
the flip flop. If R is high, then low bit (0) will be stored. The output will not change if both the
inputs are low but the undefined condition will occur if both the inputs are high.
JK flip flop: Its operation is similar to that of SR flip flop but when both the inputs J and K is
high, the stored bit toggles either from high to low or low to high.
Flip flops are generally designed to be edge triggered to prevent the unexpected behavior from
signal glitches, the inputs are checked either at the rising edge or falling edge of the clock. Glitches
represent an undesirable transition that occurs before the signal settles to its intended value.
A register stores n bits from its n bit data input which also appears at its output. A register
usually has at least two control inputs, clock and load. For a rising edge triggered register, the
inputs are only stored when load is high and clock is rising from 0 to 1. Another control input
clear may be used to resets all bits to 0 regardless of the value of input. Since all n bits of the
registers can be stored in parallel, we refer this type of register as a parallel load register.
A shift register stores n bits from its one bit data input with at least two control inputs clock and
shift. When clock is rising and shift is 1, the nth bit of input is stored in the (n-1)th bit, and (n-
6
Chapter 2 – Hardware Design Issues
1)th bit of input is stored in the (n-2)th bit and so on down to the second bit being stored in the
first bit. The first bit is shifted out appearing as an output bit. It has one bit output and the input
must be shifted into the register serially.
A counter is a register that adds binary 1 to its stored binary value. In general, a counter has a
clear, count and load as a control inputs. Clear resets all stored bits to 0 and a count input
enables incrementing on each clock edge. It often has parallel load data input and associated
load control signal. A common counter feature is both up and down counting which required an
additional control input to indicate the count direction.
A small triangle in the block represents the clock input for any sequential logic. Control inputs in
sequential logic can be either synchronous or asynchronous. A synchronous input value only has an
effect during a clock edge while an asynchronous input value affects the circuit independent of the
clock. Clear control lines are asynchronous inputs while load, shift count control lines are
synchronous inputs.
n
In
load shift count
n-bit n-bit Shift n-bit
Register Register Op Counter
clear In clear
n Op n Op
7
Chapter 2 – Hardware Design Issues
5. The output values change only with the current state, so we list the external output values only
for each possible state, regardless of the change in external input values.
6. Now, we can have a truth table, with the help of which we can proceed with combinational
design by generating minimized output equations using k-map. And finally, drawing the
combinational logic circuit.
sout
Soda Machine Inputs Outputs
Controller Cin
Q1 Q0 Cin I1 I0 Sout
0 0 0 0 0
B. State Diagram 0
0 0 1 0 1
0 Cin = 0 3 0 1 0 0 1
Cin = 0 sout =0 sout = 1 0
0 1 1 1 0
Cin = 1 1 0 0 1 0
Cin = 1 Cin = 1
0
1 0 1 1 1
1 2
1 1 0 0 0
sout = 0 Cin = 1 sout = 0
Cin = 0 \ 1
Cin = 0 1 1 1 0 1
0
D. K-map
8
Chapter 2 – Hardware Design Issues
E. Combinational Circuit
Q1 Q0 Cin
I1
I0
sout
Controller
It sets the datapath control inputs, like register load and multiplexor select signals, of the
register units, functional units, and connection units to obtain the desired configuration at a
particular time.
It monitors external control inputs as well as datapath control outputs, known as status signals,
coming from functional units, and it sets external control outputs as well.
9
Chapter 2 – Hardware Design Issues
Controller Datapath
… …
External External data
control outputs outputs
Figure 2.7: Internal View of controller and datapath of Single Purpose Processor
10
Chapter 2 – Hardware Design Issues
Assignment Statement: For this statement, a single state is used with statement
representing its action. Generally, a single arrow is used to connect to next state. The
template used for statement C = A + B is shown as an example.
C=A+B
Next
Statement
Branch Statement: It can be represented by using condition state C, join state J, and few
other states in between C and J state. State C and State J are with no actions, left empty.
But states between C state and J state contain actions. Its template can vary depending
on number of conditions defined in the problem. However, for each true condition,
there can be several states representing actions. Conditions are written along side with
the arrow that connects the C state and states of each branch. Last states of each
branch are connected to the J state.
if(C1) C:
C1 !C1*C2 !C1*!C2
C1 Statements;
else if (C2) C1 C2 Other
C2 Statements; Statements Statements Statements
else
Other statements;
J:
Loop Statement: Its template consists of Condition State C, Join State J, and other states
representing statements of loop. Condition is written alongside arrow connecting
condition state and state of first statement of loop. The last state of loop is connected to
the J state which is connected back to condition state. Complement condition is used
11
Chapter 2 – Hardware Design Issues
alongside arrow connecting C state and next statement outside of loop. The template
for the loop statement is shown in the figure below.
!cond
C:
while(cond) cond
{ Loop Statements
Loop statements;
}
Next statement;
Next statement
4. Build a Datapath: The datapath is build based on functionality of the system. Following steps
are needed to be taken into considerations while developing a datapath.
Registers: The number of registers to be used is defined by the number of variables used
in the functionality. Registers are assigned to inputs, temporary variables and output.
Functional Units: Blocks representing arithmetic and logical operations are defined
within the datapath.
Connections: The connections among ports, registers and functional units are done
based on operands used in various assignments and comparison of functionality code.
Appropriate multiplexor is required when the value in register can be assigned from
more than one source. The sources may be an input port, a functional unit, or another
register.
Control inputs and outputs: Input control signals are generally required by registers and
multiplexor. Register load signal is used in case of register while selection line signals for
multiplexor. Control output is produced by logical units of the datapath. Each control
singles are given a unique identifier.
5. Develop a Finite State Machine (FSM): The states and transitions for FSM are same as that of
FSMD. However, the complex actions and conditions of FSMD are replaced by Boolean
expressions using the control signals defined within datapath. For every register write
operations (assignment statement, arithmetic statements), register load signal is asserted and
12
Chapter 2 – Hardware Design Issues
corresponding multiplexor selection line is activated if there are two or more sources for a given
register. Also the logical operations are replaced by the control signals of its corresponding
functional block.
Example 1: Design a single purpose processor that calculates the Greatest Common Divisor (GCD) of
two numbers. Include FSMD, Datapath and FSM in the design.
Initially, the black box view diagram is drawn and then followed by the functionality which is
converted into FSMD using appropriate templates.
C. FSMD
A. Black Box View !1
1:
1 go_in
go_in x_in y_in 2:
!go_in
GCD
2J:
d_out
3: x = x_in
B. Functionality Code
int x,y; 4: y = y_in
while(1){ !(x!=y)
while(!go_in); 5:
x!=y
x = x_in;
6:
y = y_in;
x<y !(x<y)
while(x ! = y){
7: y=y-x 8: x=x-y
if(x < y)
y = y - x;
6J:
else
x = x - y; 5J:
}
d_out = x; 9: d_out = x
}
1J:
Figure 2.11: Black box view, functionality and FSMD diagram of GCD processor
13
Chapter 2 – Hardware Design Issues
x_sel
2X1 2X1
y_sel
x_ld
x y
y_ld
!= < - -
x_neq_y
x != y x<y x-y y-x
x_lt_y
d
d_ld
d_out
Figure 2.12: Datapath of GCD Processor
14
Chapter 2 – Hardware Design Issues
!go_in
0010 2J:
!(x_ne_y)
0101 5:
x_ne_y
0110 6:
x_lt_y !(x_lt_y)
0111 7: x_sel = 1, x_ld = 1 1000 8: y_sel = 1, y_ld = 1
1001 6J:
1010 5J:
1011 9: d_ld = 1
1100 1J:
15
Chapter 2 – Hardware Design Issues
16
Chapter 2 – Hardware Design Issues
3: x = x_in x = x_in
y = y_in
4: y = y_in x=y
!(x!=y)
5:
x!=y x<y x>y
6: y=y-x x=x-y
x<y !(x<y)
7: y=y-x 8: x=x-y
d_out =x
6J:
5J:
9: d_out = x
1J:
17
Chapter 2 – Hardware Design Issues
Consider the operation p = a*b*c*d, if we use single state for this particular operation then three
multipliers are required which renders system expensive and bulky. So the operation can be broken
down as x= a*b, y = c*d and p = x*y with each operations having its own state. Thus, only one
multiplier would be required in the system.
Optimizing Datapath
During the datapath design, the task of selecting a RT components for particular operation is termed
as allocation. Whereas the task of mappinig operations from the FSMD to allocated components is
termed as binding. The optimization in datapath design can be done by following ways.
Sharing of Functional Units: Single functional unit can be shared if same operations occur in
different states. For example, in computation of GCD there were two subtractor used for
two subtraction, rather a single subtractor can be used with the help of the multiplexor.
Hence one to one mapping is not necessary.
Use of Multi-functional Units: A variety of operations can be performed by ALU hence it can
be shared for different operaions occuring in different states.
18
Chapter 2 – Hardware Design Issues
State Minimization: It is the task fo merging equivalent states into a single state. Two states
are equivalent if those two states generate the same outputs and transition to the same
next state, for any given input combinations. Merging equivalent states yield exactly the
same output behaviour.
A. Truth table
Inputs Outputs B. K - map
a b c y z y bc C. Combinational Circuit
a 00 01 11 10
0 0 0 0 0
0 0 0 1 0 a
0 y
0 0 1 0 1 1 1 1 1 1 b
0 c
0 1 0 0 1 y = a + bc
0
0 1 1 1 0
0 z bc
1 0 0 1 0 z
a 00 01 11 10
0
1 0 1 1 1 0 0 1 0 1
0 1 0 1 01 1
1 1 0 1 1
0 z = ab + b’c + bc’
1 1 1 1 1
0
Figure 2.15: Truth table, K-map, and combinational circuit
19
Chapter 2 – Hardware Design Issues
Problem 2: Design a 2-bit comparator with a single output “less than”, using the combinational
design technique described in the chapter. Start from a truth table, use K-maps to minimize logic
and draw the final circuit.
Solution: As the comparator is 2 – bit, there must be total of four inputs; two inputs each of two
bits. And only less than condition is to be checked, so only single output must be defined. Then the
general steps for designing a combinational logic circuit is followed.
A. Truth table
a1 a0 b1 b0 lt B. K - map
0 0 0 0 0 a1a0
0 b1b0 00 01 11 10
0 0 0 1 1
0 00 0 0 0 0
0 0 1 0 1
0 01 1 0 0 0
0 0 1 1 1
0 11 1 1 0 1
0 1 0 0 0
10 1 1 0 0
0 1 0 1 0
lt = b1a1’ + b0a1’a0’ + b1b0a0’
0 1 1 0 1
0 1 1 1 1
1 0 0 0 0 C. Combinational Circuit
1 0 0 1 0
a1
1 0 1 0 0 a0
1 0 1 1 1 b1
1 1 0 0 0
b0
1 1 0 1 0
1 1 1 0 0
1 1 1 1 0
Figure 2.16: Truth table, K-map and combinational circuit for two bit comparator
20
Chapter 2 – Hardware Design Issues
Problem 3: Construct a pulse divider. Slow down your pre-existing pulse so that you output a 1
every four pulses detected.
Solution:
A. State Diagram B. Implementation Model
a=1 Q1 Q0
a=1
State Registers
1 2
a=1 I1 I0
a=0 x=0 x=0 a=0
Inputs Outputs Q1 Q0 a
Q1 Q0 a I1 I0 x
0 0 0 0 0
0
0 0 1 0 1
0 1 0 0 1 I1
0
0 1 1 1 0
1 0 0 1 0
0
1 0 1 1 1
I0
1 1 0 1 1
1
1 1 1 0 1 x
D. K - map
I1 Q1Q0 I0 Q1Q0 x Q1Q0
00 01 11 10 00 01 11 10 00 01 11 10
a 0 0 0 1 1 a 0 0 1 1 0 a 0 0 0 1 0
1 0 1 0 1 1 1 0 0 1 1 0 0 1 10
I1 = Q1’Q0a + Q1a’ + Q1Q0’ I0 = Q0a’ + Q0’a x = Q1Q0
Figure 2.17: Pulse Divider – State diagram, state table, K-map, combinational circuit
21
Chapter 2 – Hardware Design Issues
Problem 4: Design a single purpose processor that calculates x to the power n (xn). Include FSMD,
Datapath and FSM in the design.
Solution:
while(1){ 4: n = n_in
while(!go_in);
5: m=1
x = x_in;
n = n_in; !(n>0)
6:
m = 1;
n>0
while(n>0){
7: m=m*x
m = m * x;
n = n - 1; 8: n=n-1
}
p_out = m; 6J:
}
p_out = m
9:
1J:
Figure 2.18: The black box view, functionality and FSMD for processor that calculates xn.
22
Chapter 2 – Hardware Design Issues
x_in n_in
1
n_sel
2X1 2X1
m_sel
x_ld
x n m
n_ld
m_ld
0 1
> - *
n_gt_0 n>0 n-1 m*x
p_ld
p
p_out
Figure 2.19: Datapath
23
Chapter 2 – Hardware Design Issues
!1
0000 1:
1 go_in
0001 2:
!go_in
0010 2J:
0011 3: x_ld = 1
n_sel = 0
0100 4:
n_ld = 1
m_sel = 0
0101 5:
m_ld = 1
!(n_gt_0)
0110 6:
n_gt_0
m_sel = 1
0111 7:
m_ld = 1
n_sel = 1
1000 8:
n_ld = 1
1001 6J:
1010 9: p_ld = 1
1011 1J:
24
Chapter 2 – Hardware Design Issues
Problem 5: Design a single purpose processor that generates Fibonacci series up to n places. Start
with a function that computes desired result, translate the function into a state diagram, sketch a
probable datapath, and draw FSM diagram.
Solution:
A. Black Box View C. FSMD
!1
1:
go_in n_in
1 go_in
FIBONACCI 2:
f_out !go_in
2J:
3: n = n_in
B. Functionality Code
int ft, st, nt, count, n; 4: ft = 0
while(1){
5: st = 1
while(!go_in);
6: count = 1
n = n_in;
!(count<=n)
ft = 0; 7:
st = 1; count<=n
count = 1; 8: f_out = ft
while(count <= n){
9: nt = ft + st
f_out = ft;
nt = ft + st; 10: ft = st
ft = st;
11: st = nt
st = nt;
1J:
Figure 2.21: Fibonacci series generator – the black box view, functionality and FSMD
25
Chapter 2 – Hardware Design Issues
st_ld
nt_ld
n_ld
inc + <=
c_le_n ft+st c<=n
f
f_ld
f_out
Figure 2.22: Datapath for Fibonacci series generator
26
Chapter 2 – Hardware Design Issues
!1
0000 1:
1
go_in
0001 2:
!go_in
0010 2J:
0011 3: n_ld = 1
1000 8: f_ld = 1
1001 9: nt_ld = 1
1101 7J:
1110 1J:
27