C7 · Lesson 13 · Combinational logic
Building functions from gates
A combinational circuit's outputs depend only on its present inputs: no memory. Adders, multiplexers, decoders and comparators are all combinational, and together they make up the "arithmetic and logic unit" at the heart of a processor. Designing one means getting from a truth table to a small set of gates, and the classic tool for that is the Karnaugh map, which turns algebraic simplification into spotting rectangles.
Play
- A 2-bit adder: two full-adder stages, where the carry out of the low bit feeds the high bit. Flip the switches to set A (A1 A0) and B (B1 B0).
- Check a few sums against the truth table. Which output is the carry out of the whole adder?
- Follow the carry from the low stage. When does it make a difference to the high bits?
Predict
A function of three inputs is 1 exactly when C is 1, whatever A and B are. How many of its 8 truth-table rows are 1?
Four: the rows with C = 1. On a Karnaugh map, those four 1s form a single rectangle covering every combination of A and B, so they simplify to just C. A K-map's job is exactly this: group 1s into the biggest possible rectangles of 1, 2, 4 or 8 cells, each of which becomes one simple product term.
Name it
Designing combinational logic
From a truth table to a sum of products. Each row where the output is 1 is a minterm: an AND of all inputs, each plain or inverted. OR them together and you have the function. It's correct, but rarely small.
Karnaugh maps. Arrange the truth table in a grid whose rows and columns are in Gray-code order (00, 01, 11, 10), so neighboring cells differ in one input, including wrapping around the edges. Then:
- group the 1s into rectangles whose sides are powers of 2, as large as possible, overlapping if useful;
- each rectangle is one AND term, keeping only the inputs that stay the same across it;
- OR the terms.
A group of 2 drops one input, a group of 4 drops two.
Building blocks:
- Multiplexer (mux): selects one of inputs by an n-bit select. A 2:1 mux is .
- Decoder: n inputs, outputs, exactly one active: used to pick a memory chip or a register.
- Half adder: , . Full adder: , .
- Ripple-carry adder: n full adders in a chain, each carry feeding the next; simple but slow (lesson 19).
Worked example
A full adder gets A = 1, B = 1 and carry-in 0. What are its sum and carry?
Show the solution
- Sum.
- Carry.
- Check. 1 + 1 = 10 in binary.
Answer the sum is 0 and the carry is 1.
Worked example
Minimize for inputs A, B, C.
Show the solution
- Find the block. Every odd row is a 1, and the four cells form a block in which A and B both vary.
- Read the term. Only C stays the same across the block, so the function is just C.
Answer .
Worked example
Design a majority function of three inputs: 1 when at least two are 1. How many two-input NAND gates does it take?
Show the solution
- Find the rows. The output is 1 in rows 3, 5, 6 and 7.
- Minimize. Each 1 pairs with another to give the full adder's carry.
- First level of NANDs. Three NAND2 gates make , and .
- Combine the three. A NAND of all three gives M, which needs a three-input NAND, or two more NAND2 gates and an inverter: gates using only two-input NANDs.
- Where it's used. Majority voting is how triple-redundant systems outvote one failed copy.
Answer , which takes 6 two-input NAND gates.
Check
A function of A, B and C is 1 for rows 1, 3, 5 and 7 (counting from 0 with A as the top bit). Write it as simply as possible.
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
A 2:1 multiplexer outputs A when S = 0 and B when S = 1. Write its output.
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
Simplify .
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
How many outputs does a 4-input decoder have?
Check
Add 011 and 001 in binary. Give a 4-bit result.
Check
Write the three-input majority function.
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Check
Write a function that's 1 when A = B and C = D, using XOR, AND and NOT.
Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.
Explain why
Why do neighboring cells in a Karnaugh map differ in only one input, and why does that matter?
The rows and columns are ordered so that each step changes just one input, including the wrap-around at the edges. Two 1s in neighboring cells then share every input but one, and since that one input appears both plain and inverted, the two minterms combine into a single term without it, by the rule . Grouping a rectangle of neighbors is therefore the same as applying that algebra repeatedly, but by eye.
Practice
Keep practicing
5 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.