Building Computer CircuitsBuilding Computer Circuits
Chapter 4.4Chapter 4.4
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 2
PurposePurpose• We have looked at so far how to build logic We have looked at so far how to build logic
gates from transistors.gates from transistors.• Next we will look at how to build circuits from Next we will look at how to build circuits from
logic gates, for example:logic gates, for example:– A circuit to check if two numbers are equal.A circuit to check if two numbers are equal.– A circuit to add two numbers.A circuit to add two numbers.
• Gates will become our new building blocks:Gates will become our new building blocks:– Human body:Human body: cells cells organs organs body body– Computers:Computers: gates gates circuits circuits computer computer
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 3
CircuitCircuit
• A A circuitcircuit is a collection of interconnected logic is a collection of interconnected logic gates:gates:– that transforms a set of binary inputs into a set of that transforms a set of binary inputs into a set of
binary outputs, andbinary outputs, and– where the values of the outputs depend only on the where the values of the outputs depend only on the
current values of the inputscurrent values of the inputs• These kind of circuits are more accurately calledThese kind of circuits are more accurately called
combinatorial circuitscombinatorial circuits..
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 4
Circuit (external view)Circuit (external view)• A circuit can have any number of inputs and outputs:A circuit can have any number of inputs and outputs:
– Number of inputs and outputs can differ.Number of inputs and outputs can differ.– The inputs and outputs are either 0 or 1.The inputs and outputs are either 0 or 1.
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 5
Circuit (external view Circuit (external view cont.)cont.)
• Output depends only on current input valuesOutput depends only on current input values– Each set of input always generates the same output.Each set of input always generates the same output.– Different sets of input can generate identical output.Different sets of input can generate identical output.
INPUT OUTPUT
CIRCUIT
0
0
0
1
0
1
1
1
1
0
1
0
1
1
1
1
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 6
Circuit (internal view)Circuit (internal view)• Circuits are build from interconnected Circuits are build from interconnected ANDAND, , OROR and and
NOTNOT gates, in a way such that each input combination gates, in a way such that each input combination produces the desired output.produces the desired output.
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 7
ExampleExample• What are the output values What are the output values cc and and dd given input given input
values values aa=1=1, , bb=0=0??
1 1
00
a
b
c
d
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 8
Circuit Diagrams and Circuit Diagrams and Boolean ExpressionsBoolean Expressions
• The diagrams we were looking at are called The diagrams we were looking at are called circuit diagramscircuit diagrams..• Relationship between circuit diagrams and Boolean expr.:Relationship between circuit diagrams and Boolean expr.:
– Every Boolean expression can be represented pictorially Every Boolean expression can be represented pictorially as a circuit.as a circuit.
– Every output in a circuit diagram can be written as a Every output in a circuit diagram can be written as a Boolean expression.Boolean expression.
• Example (output values c and d from previous diagram):Example (output values c and d from previous diagram):– c = ( a OR b)c = ( a OR b)– d = NOT ( (a OR b) AND (NOT b) )d = NOT ( (a OR b) AND (NOT b) )
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 9
Circuits Diagram and Circuits Diagram and Boolean ExpressionsBoolean Expressions
• Deriving Boolean expressions for the output.Deriving Boolean expressions for the output.
NOT ((a OR b) AND (NOT b))
(a OR b) (a OR b)a
b
(a OR b) AND (NOT b)
(NOT b)
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 10
Circuits Diagram and Circuits Diagram and Boolean ExpressionsBoolean Expressions
• Remember, when writing Boolean expressions for Remember, when writing Boolean expressions for circuit diagrams, we use a different notation!circuit diagrams, we use a different notation!
(a + b) (a + b)a
b
b
(a + b) · b
(a + b) · b
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 11
ExampleExample
• What Boolean expression describes the output?What Boolean expression describes the output?
ab
a·b
a·b
a·b + a·b
b
a
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 12
Constructing CircuitsConstructing Circuits
• How do we design and construct circuits?How do we design and construct circuits?– We first have to know what we want the circuit to do!We first have to know what we want the circuit to do!– This implies, that for all possible input combinations This implies, that for all possible input combinations
we must decide what the output should be. we must decide what the output should be. • Once we know that, there exists methods we can Once we know that, there exists methods we can
use to design the layout of the circuit.use to design the layout of the circuit.– We will look at one such method called, sum-of-We will look at one such method called, sum-of-
products algorithm.products algorithm.
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 13
Sum-of-Products AlgorithmSum-of-Products Algorithm
Step 1: Truth Table ConstructionStep 1: Truth Table ConstructionRepeat steps 2, 3 and 4 for each output columnRepeat steps 2, 3 and 4 for each output column
Step 2: Sub-expression construction using AND and NOT gatesStep 2: Sub-expression construction using AND and NOT gatesStep 3: Sub-expression combination using OR gatesStep 3: Sub-expression combination using OR gatesStep 4: Circuit Diagram ProductionStep 4: Circuit Diagram Production
Step 5: Combine Circuit DiagramsStep 5: Combine Circuit DiagramsStep 6: Optimize Circuit (optional)Step 6: Optimize Circuit (optional)Step 7: StopStep 7: Stop
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 14
Step 1: Truth Table Step 1: Truth Table ConstructionConstruction
• Decide what the circuit is supposed to do:Decide what the circuit is supposed to do:– treat the circuit itself as a “black box”treat the circuit itself as a “black box”– only interested in input/output signalsonly interested in input/output signals
Circuit
0
0
0
0
1
0
0
1
0
0
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 15
Step 1 (cont.)Step 1 (cont.)
Inputs Outputsa b c 1 20 0 0 0 10 0 1 0 00 1 0 1 10 1 1 0 11 0 0 0 01 0 1 0 01 1 0 1 11 1 1 0 0
3 inputs 3 inputs 2 233 = 8 = 8 possibilitiespossibilities
• Write the desired output for all possible input Write the desired output for all possible input combinations:combinations:
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 16
Step 2: Sub-expression Step 2: Sub-expression ConstructionConstruction
• For each output (separately):For each output (separately):– Use AND and NOT gates to construct a sub-Use AND and NOT gates to construct a sub-
expression for rows where the output is 1expression for rows where the output is 1Inputs Outputsa b c 1 20 0 0 0 10 0 1 0 00 1 0 1 10 1 1 0 11 0 0 0 01 0 1 0 01 1 0 1 11 1 1 0 0
Case 1
Case 2
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 17
Step 2 (cont.)Step 2 (cont.)• Look at the inputs, if the value isLook at the inputs, if the value is
– 1 then use input as is in sub-expression, ( e.g. 1 then use input as is in sub-expression, ( e.g. b b ))– 0 then use input value 0 then use input value complementedcomplemented ( e.g. ( e.g. a a ))
a b c 1… … … …0 1 0 1… … … …1 1 0 1… … … …
aabbcc
aabbcc
• Why do it this way?Why do it this way?Each expression will evaluate to 1 for given input Each expression will evaluate to 1 for given input combination (row), but 0 for all other inputs!combination (row), but 0 for all other inputs!
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 18
Step 3: Sub-expression Step 3: Sub-expression CombinationCombination
• Use OR gates to combine the sub-expressions Use OR gates to combine the sub-expressions from previous step into one expressionfrom previous step into one expression
( a( abbc ) + ( ac ) + ( abbc )c )
• This expression will evaluate to 1 for all input This expression will evaluate to 1 for all input combinations that have 1 as output, but 0 for all combinations that have 1 as output, but 0 for all the other input combinations (rows)!the other input combinations (rows)!
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 19
Step 4: Circuit Diagram Step 4: Circuit Diagram ProductionProduction
• Construct a circuit diagram from the expression Construct a circuit diagram from the expression generated in previous step:generated in previous step: ( a( abbc ) + ( ac ) + ( abbc )c )
a
b
c
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 20
Repeat steps 2, 3, and 4 Repeat steps 2, 3, and 4 for each outputfor each output
• We need to repeat steps 2, 3, 4 for each output.We need to repeat steps 2, 3, 4 for each output.• In our example, there is one more output:In our example, there is one more output:
– Step2: Four sub-expressions, one for each row:Step2: Four sub-expressions, one for each row:
– Step 3: Combine sub-expressions using + (OR):Step 3: Combine sub-expressions using + (OR):
– Step 4: Draw circuit diagram Step 4: Draw circuit diagram ( a( abbc ) + ( ac ) + ( abbc ) + ( ac ) + ( abbc ) + ( ac ) + ( abbc )c )
aabbc ac abbc ac abbc ac abbcc
(see p. 694 in text-book)(see p. 694 in text-book)
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 21
Combine Individual Combine Individual CircuitsCircuits
• Combine the circuits for each individual output Combine the circuits for each individual output into an one larger circuit.into an one larger circuit.
Circuit for Output 1abc
Output 1
Circuit for Output 2 Output 2
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 22
Optimize the CircuitOptimize the Circuit• A circuit build using this algorithm will generate the A circuit build using this algorithm will generate the
correct output, but it uses unnecessarily many gatescorrect output, but it uses unnecessarily many gates– Why is that important?Why is that important?– Typically we need to optimize the circuit, by minimize the Typically we need to optimize the circuit, by minimize the
number of gates used.number of gates used.• An optimized circuit for the example would look like:An optimized circuit for the example would look like:
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 23
Example 1: Compare-for-Example 1: Compare-for-Equality Circuit (N-CE)Equality Circuit (N-CE)
• We want to build a circuit that checks if two We want to build a circuit that checks if two numbers are the same?numbers are the same?
00 00 00 00 00 00 00 00 00 00 00 00 11 11 11 00
00 00 00 00 00 00 00 00 00 00 00 00 11 11 11 00
= ===…
– The same number if and only if The same number if and only if allall corresponding bits are the corresponding bits are the identical.identical.
• First step is to build a circuit that compares two bits (can First step is to build a circuit that compares two bits (can then use 16 of those to compare two 16-bit numbers!)then use 16 of those to compare two 16-bit numbers!)
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 24
Ex1 --Ex1 -- Step 1: Truth table Step 1: Truth table constructionconstruction
• The circuit to compare two bits has:The circuit to compare two bits has:– two inputs (the value of the two bits)two inputs (the value of the two bits)– one output (0 if the bits are different, 1 if the bits are same)one output (0 if the bits are different, 1 if the bits are same)
Inputs Outputa b0 00 11 01 1
1001
1-CE00
1100
• How does the truth-table look like?How does the truth-table look like?
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 25
Example 1:Example 1: Step 2 Step 2 Construct sub-expressionsConstruct sub-expressions
• Construct a Boolean expression for each row in Construct a Boolean expression for each row in the table where the output is one:the table where the output is one:
Inputs Output
a b
0 0 1
0 1 0
1 0 0
1 1 1
aabb
aabb
==
==
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 26
Example 1: Step 3 and 4Example 1: Step 3 and 4
• Combine into one sub-expression using OR (+)Combine into one sub-expression using OR (+)
( a( ab ) + ( ab ) + ( ab )b )• Draw a circuit diagramDraw a circuit diagram
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 27
Repeat for each outputRepeat for each output• Need to repeat step 2, 3, 4 for all outputs: Need to repeat step 2, 3, 4 for all outputs:
– There is only one output, so we are done!There is only one output, so we are done!• So our 1-bit compare circuit ( 1-CE ) looks like:So our 1-bit compare circuit ( 1-CE ) looks like:
• But we want to compare N-bit sized numbers? But we want to compare N-bit sized numbers?
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 28
N-bit compareN-bit compare
00
11
11
11
..
00
00
11
11
11
..
00
aa bb
11
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 29
Example 2: An Addition Example 2: An Addition Circuit (N-add)Circuit (N-add)
• We want to build a circuit that adds two integers.We want to build a circuit that adds two integers.• How do we add two binary numbersHow do we add two binary numbers
– the same way as decimal numbers (but different base)the same way as decimal numbers (but different base)
00 11 11 00 11 00 11 00
00 11 11 00 11 11 00 00
0011110011001111
111111
++
aa
bb
ss
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 30
Example 2: 1-ADDExample 2: 1-ADD
• Let’s start by building a circuit that adds three Let’s start by building a circuit that adds three bits (two bits + carry)bits (two bits + carry)
• We can then use N of these 1-ADD circuits to We can then use N of these 1-ADD circuits to add any two N-bit integers.add any two N-bit integers.
1-ADD1111
11
00a =a =
00
b =b =
carry =carry == carry= carry
= s= s
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 31
Ex2--Ex2-- Step 1: Truth table Step 1: Truth table constructionconstruction
Inputs Outputs
a b c s c
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
0 0
1 0
1 0
0 1
1 0
0 1
0 1
1 1
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 32
Example 2:Example 2: Step 2-3 Step 2-3 (output 1)(output 1)
• Construct a Boolean expression for each 1-rowConstruct a Boolean expression for each 1-rowInputs Outputs
a b c s0 0 0 00 0 1 10 1 0 10 1 1 01 0 0 11 0 1 01 1 0 01 1 1 1
aabbccaabbccaabbcc
aabbcc• Combine into one Boolean expressionCombine into one Boolean expression
s = (as = (abbc) + (ac) + (abbc) + (ac) + (abbc) + (ac) + (abbc) c)
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 33
Example 2: Step 4 Circuit Example 2: Step 4 Circuit Diagram (output 1)Diagram (output 1)
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 34
Example 2:Example 2: Step 2-3-4 Step 2-3-4 (output 2)(output 2)
• Step2 : Construct a Boolean expression for each 1-rowStep2 : Construct a Boolean expression for each 1-rowa b c carry0 0 0 00 0 1 00 1 0 00 1 1 11 0 0 01 0 1 1
1 1 0 1
1 1 1 1
aabbcc
aabbccaabbccaabbcc
• Step 3: Combine into one Boolean expressionStep 3: Combine into one Boolean expressions = ( as = ( abbc ) + ( ac ) + ( abbc ) + ( ac ) + ( abbc ) + ( ac ) + ( abbc ) c )
• Step 4: Draw a circuit diagram (not shown)Step 4: Draw a circuit diagram (not shown)
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 35
Example 2: Combining Example 2: Combining output 1 and 2 circuitsoutput 1 and 2 circuits
ss
carrycarry
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 36
Example 2: N-ADDExample 2: N-ADD
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 37
Example 2: Optimize the Example 2: Optimize the circuitcircuit
• Each 1-ADD circuit has 25 gates (47 transistors)Each 1-ADD circuit has 25 gates (47 transistors)– 16 AND gates 16 AND gates ( x 2 transistors)( x 2 transistors)– 6 OR games 6 OR games ( x 2 transistors)( x 2 transistors)– 3 NOT gates 3 NOT gates ( x 1 transistors)( x 1 transistors)
• To add two 32-bits bits integers we needTo add two 32-bits bits integers we need– 32 1-ADD circuits 32 1-ADD circuits 32 * 25 = 800 gates 32 * 25 = 800 gates 1504 1504
transistorstransistors• Optimized 32-bits addition circuit in modern Optimized 32-bits addition circuit in modern
computers uses: computers uses: 500-600 transistors500-600 transistors– We will not learn how to optimize circuits in this courseWe will not learn how to optimize circuits in this course
Control CircuitsControl Circuits
Chapter 4.5Chapter 4.5
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 39
Control CircuitsControl Circuits• So far we have seen two types of circuits:So far we have seen two types of circuits:
– Logical ( is a = b ?)Logical ( is a = b ?)– Arithmetic ( c = a + b)Arithmetic ( c = a + b)
• Computers use many different logical (Computers use many different logical (>, <, >=. >, <, >=. <=, !=, …<=, !=, …), and arithmetic (), and arithmetic (+,-,*,/+,-,*,/) circuits.) circuits.
• There are also different kind of circuits that are There are also different kind of circuits that are essential for computers essential for computers control circuitscontrol circuits– We will look at two different kind of control circuits, We will look at two different kind of control circuits,
multiplexorsmultiplexors and and decoders.decoders.
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 40
MultiplexorMultiplexor• A multiplexor circuit has:A multiplexor circuit has:
– 22N input lines (numbered 0, …, 2input lines (numbered 0, …, 2NN-1)-1)– 1 1 output lineoutput line– N N selector linesselector lines
• The selector lines are used to choose which of The selector lines are used to choose which of the input signals becomes the output signal:the input signals becomes the output signal:– Selector lines interpreted as an N-bit integerSelector lines interpreted as an N-bit integer– The signal on the input line with the corresponding The signal on the input line with the corresponding
number becomes the output signal.number becomes the output signal.
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 41
Multiplexor (cont.)Multiplexor (cont.)
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 42
Multiplexor (cont.)Multiplexor (cont.)
Multiplexor
0
1
0
1
0
00
1
10
0
01
1
11
0
1
2
3
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 43
DecoderDecoder• A decoder circuit has:A decoder circuit has:
– N N input lines (numbered 0, 1, …., N-1)input lines (numbered 0, 1, …., N-1)– 22NN output line (numbered 0, 1, … 2output line (numbered 0, 1, … 2NN-1)-1)
• Works as follows:Works as follows:– The N input lines are interpreted as a N-bit integer The N input lines are interpreted as a N-bit integer
value. value. – The output line corresponding to the integer value is The output line corresponding to the integer value is
set to 1, all other to 0set to 1, all other to 0
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 44
Decoder (cont.)Decoder (cont.)
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 45
Decoder (cont.)Decoder (cont.)
Decoder
0
0
1
00001000
0
1
2
3
4
7
5
6
0
1
2
100 = 4
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 46
SummarySummary
• We looked at how computers represent data:We looked at how computers represent data:– Internal vs External RepresentationInternal vs External Representation– Basic storage unit is a binary digit Basic storage unit is a binary digit bitbit– Data is represented internally as Data is represented internally as binary databinary data..– Use the binary number system.Use the binary number system.
• We learned why computers use binary data:We learned why computers use binary data:– Main reason is Main reason is reliabilityreliability– Electronic devices work best in bi-stable Electronic devices work best in bi-stable
environment.environment.
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 47
Summary (cont.)Summary (cont.)
• We looked at the basic building blocks used in We looked at the basic building blocks used in computers:computers:– Binary Storage Device = TransistorBinary Storage Device = Transistor
• We saw how to build logic gates (AND, OR, NOT):We saw how to build logic gates (AND, OR, NOT):– Transistors Transistors Gates Gates– Boolean logicBoolean logic
• We saw how to build circuits:We saw how to build circuits:• Gates Gates Circuits Circuits• Looked at logical, arithmetic, and control circuits.Looked at logical, arithmetic, and control circuits.
CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 48
Summary (cont.)Summary (cont.)
• Now that we have seen the basic building blocks Now that we have seen the basic building blocks (low-level view), in the next chapter we will look (low-level view), in the next chapter we will look at the at the “big picture” “big picture” (high-level view)(high-level view)..
• We will look at the basic architecture underlying We will look at the basic architecture underlying design of all computers:design of all computers:– Look at higher level computer components, such as Look at higher level computer components, such as
processors and memory. processors and memory. – Understand better how computers execute Understand better how computers execute
programs.programs.