11.
1 Combinatorial Circuits
11.1 Combinatorial Circuits
• Logic Gates
• Combinatorial Circuits
Logic gates
A gate implements a simple boolean function.
• Such as AND, OR or NOT.
• Constructed using a few transistors.
It's the basic building block of digital design.
AND OR
x x
x.y x+y
y y
NOT XOR
x
x x' x⊕y
y
the circle represents complement
3
Universal gates
Recall that all other gates can be constructed using NAND gates alone, or NOR gates alone.
So these are our universal gates.
NAND NOR
x x
(x.y)' (x+y)'
y y
4
Gates with multiple inputs
OR gates with multiple inputs. AND gates with multiple inputs.
• 1 if any input is 1. • 1 for exactly 1 set of input values.
• 0 if all inputs are 0.
OR AND
x x
y x+y+z y x.y.z
z z
5
Digital circuits
We can build boolean functions using gates:
F(x, y, z) = y + x'.z
y
x F
z
And using sum of products can make construction simple:
x
F = x'.y.z + x.y.z + x.y.z'
y F
z
6
Subtle uses of logic gates
The functionality we see in high-level languages is built upon lower level circuits.
Sometimes this can be exploited to improve efficiency and performance.
SWAP
Using XOR to swap 2 variables' values:
x = x XOR y x x
y = x XOR y
y y
x = x XOR y
input output
Using AND to mask bits: MASK
• set the bits that you want to keep to 1 in the mask mask 0 0 0 0 1 1 1 1
• set others to 0 word 1 1 0 0 0 1 1 0
• then AND with the word
result 0 0 0 0 0 1 1 0
7
Integrated circuits
A modular approach.
We've seen that individual gates can be combined to perform more complex functions.
• However gates aren't usually manufactured individually.
• But instead a collection of them are etched onto an integrated circuit (IC).
We use one or many of these ICs to create a boolean function.
8
IC Small Scale Integration (SSI) example
Here's an integrated chip with just four NAND gates.
(Note that modern chips have VLSI or ULSI.)
1 2 3 4 5 6 7
9
Implementing a function on the simple IC
F(x,y) = x+y
F= x+y
converted to just NANDs
= ((x.x)'.(y.y)')'
1 2 3 4 5 6 7
x y
10
A word about notation
boolean classic course text
Throughout these slides we are using the classic symbols
function symbol symbol
for logic gates.
The course text uses non-standard symbols. NOT x ¬ x'
They are equivalent.
x y
NOR (x + y )' (x + y )'
NOR
x y
OR x+y
OR
x y
AND AND
xy
11.1 Combinatorial Circuits
• Logic Gates
• Combinatorial Circuits
Combinatorial circuits
The examples we've seen so far are combinatorial circuits.
The output is based entirely upon the input values.
Q. Why combinatorial circuits?
A. They are accurate, reliable, general purpose, fast and cheap.
They produce an output at the (notional) instant when the input values are specified.
They have no feedback (no loops).
• So all input values must arrive at the same time for them to work.
• They can't 'remember' the inputs if some arrive later than others.
We'll see later what to do if the inputs arrive sequentially.
For now we'll look at some useful combinatorial circuits.
13
Half-adder
We want to be able to add binary numbers in the Arithmetic Logic Unit (ALU).
Let's start with a half-adder which can add two bits together:
x y Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Q. So could we simply combine a set of half-adders to perform addition on words of any size we choose?
A. No, because we need to account for the carry in.
14
Full-adder
A full-adder takes account of the carry in...
x y Carry In Sum Carry Out
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
...and we can see how the half-adder got it's name.
15
Ripple-carry adder
The full-adder can be combined to create a ripple-carry-adder which can add words together.
Note that in reality we now have far more efficient adders (40%-90% faster!) through the use of
optimisations based upon parallelisation and handling of the carry bit.
16
Decoder
Uses the combination of the input values to select one specific output line.
So, with two inputs x and y, there are 4 possible combinations:
x.y, x.y', x'.y, x'.y'
And we create an output line for each:
This is useful for building circuits which can determine:
• Which memory address to access.
• Which function to perform based upon the input.
17
Pop quiz: Decoder
A decoder must be designed to select one of 30 circuits.
Q. How many input lines does it need?
A. 5, because choosing between 30 circuits requires 30 input patterns.
• With 1 input line we can represent 2 patterns, 0 and 1,
• With 2 input lines we can represent 4 patterns, 00, 01, 10, and 11,
• With 3 input lines we can represent 8 patterns, 000 to 111, and so on.
• With 5 input lines we can repesent 32 patterns, 00000 to 11111, which is enough.
Q. How many output lines does it need? in general, we need n such that 2n ≥ 30
A. 30 - one for each circuit.
Think of this as needing to send a separate activation signal to each circuit.
18
Multiplexer
Selects a single output from several inputs.
Uses control lines to determine which input to route.
Like the inputs & output of a home theatre receiver.
19
Pop quiz: Multiplexer
Suppose that a multiplexer takes 10 inputs and selects one for output.
Q. How many input lines does it have?
A. 10, one for each input.
Q. How many control lines does it need?
A. 4, because it needs 10 different patterns to select between the inputs, and 24 ≥ 10.
Q. How many output lines does it have?
A. 1, because there's always just one output line.
20
Simple 2-bit ALU
Control Codes:
00 = A + B
01 = NOT A
10 = A OR B
11 = A AND B
21
Simple 2-bit ALU example: OR enabled
0 1 1 0
OR function enabled:
• Function code: 10
• Inputs: 01 & 10
• Output: 11
1
1 1 22
To conclude
We can build complex circuits in a modular fashion.
• Either by combining individual gates.
• Or by combining integrated circuits.
But so far these circuits require that the inputs arrive and are handled at the same time
• They are memoryless.
So next lecture we'll see how to account for memory and timing needs.
23
Reading and References
Required Reading
• Course textbook chapter 7.3
Other material used for reference
• Chapter 3, Computer Organization & Architecture (3rd Edition), Null & Lobur
• Chapter 3, Fundamentals of Computer Architecture, Burrell
(again, you don't need access to those texts; the course text is sufficient)
Suggested learning activities:
• Make sure that you understand how the full adder works.
• Perhaps trace the flow for a 4-bit adder.
• Try to follow instructions through the simple 2-bit ALU.
24