C716 of 57
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C7 · Lesson 16 · Combinational building blocks

Decoders, encoders, multiplexers and comparators

Nobody designs a processor gate by gate. They assemble it from a handful of standard blocks, each a few gates, each used thousands of times: decoders that turn a number into one active line, encoders that do the reverse, multiplexers that pick one of several inputs, and comparators that test whether two numbers are equal or which is larger. A multiplexer is even a universal block: with the right constants on its data inputs it computes any function of its select lines, which is exactly how FPGAs implement logic (lesson 45).

  • F is a function of A, B and C written as a sum of minterms, ∑m(1,2,6,7). M computes the same function with a 4:1 multiplexer: A and B select one of four data inputs, which are C, C¯, 0 and 1.
  • The truth tables match. Each data input is just the function's value for that row pair, written in terms of C.

Predict

How many select lines does a 32-to-1 multiplexer need?

Name it

Decoders and encoders

An n-to-2n decoder activates exactly the output whose number is on its inputs: output k is the minterm mk. With an enable input E, every output is ANDed with E, which lets two 2:4 decoders and an inverter make a 3:8 decoder (the top address bit enables one or the other). Decoders select memory chips, registers and instructions.

An encoder does the reverse, turning one active line of 2n into its n-bit number. A priority encoder handles several active inputs by reporting the highest-priority one, with a valid output for "any input active". For four inputs with I3 highest: Y1=I3+I2, Y0=I3+I¯2I1, valid =I3+I2+I1+I0.

Multiplexers

A 2n:1 multiplexer routes data input k to its output when the select lines hold k: Y=∑kmk(S)Dk. Larger ones are built as trees of 2:1 muxes.

As a function generator: any function of n variables is a 2n:1 mux with the truth table's outputs (0s and 1s) on its data inputs, a lookup table. Better, a 2n−1:1 mux driven by n − 1 of the variables, with each data input set to 0, 1, the last variable or its complement. A demultiplexer sends one input to the selected one of 2n outputs: a decoder with its enable used as the data input.

Comparators

Equality: two n-bit numbers are equal when every bit pair matches: EQ=∏iAi⊕Bi¯. Magnitude: A > B when, scanning from the top bit, the first differing bit has Ai=1. For two bits:

A>B=A1B¯1+A1⊕B1¯A0B¯0

In practice a subtractor's borrow does the same job (lesson 17).

Worked example

Implement f(A,B,C)=∑m(1,2,6,7) with a 4:1 mux selected by A and B.

Show the solution
  1. Rows 0 and 1 (AB = 00). They give f = 0, 1, so D0=C.
  2. Rows 2 and 3 (AB = 01). They give 1, 0, so D1=C¯.
  3. Rows 4 and 5 (AB = 10). They give 0, 0, so D2=0.
  4. Rows 6 and 7 (AB = 11). They give 1, 1, so D3=1.

Answer D0=C, D1=C¯, D2=0 and D3=1: the circuit M in the sim.

Worked example

Build a 4-to-16 decoder from 2-to-4 decoders with enables. How many?

Show the solution
  1. First level. One 2:4 decoder on the top two bits drives the enables of four more.
  2. Second level. The four 2:4 decoders on the bottom two bits each produce four of the sixteen outputs.
  3. Count them. 1+4=5

Answer five 2-to-4 decoders.

Worked example

An 8-input priority encoder (input 7 has the highest priority) sees the inputs 0010 1100, input 7 on the left. What does it output?

Show the solution
  1. Find the active inputs. Reading 0010 1100 with input 7 on the left, inputs 5, 3 and 2 are active.
  2. Pick the highest. The highest-numbered active input wins, so the output is 5, binary 101, and the valid flag is 1; inputs 3 and 2 are ignored.
  3. Where it's used. Interrupt controllers use exactly this: several devices can request at once, and the encoder reports the most urgent.
  4. No input active. The valid flag goes to 0, which tells the reader that the 000 on the output means nothing.

Answer 101 (input 5), with the valid flag at 1.

Check

How many outputs does a decoder with 5 inputs have?

Check

How many select lines does a 16:1 multiplexer need?

Check

A 2:4 decoder with enable E has inputs A (top bit) and B. Write its output Y2.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

A priority encoder has inputs I3 (highest priority) down to I0. Write its low output bit Y0.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

Write an equality comparator for the 2-bit numbers A1A0 and B1B0.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

Write A > B for the 2-bit numbers A1A0 and B1B0.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

A function of A, B and C is built from a 4:1 mux selected by A and B. For the rows with AB = 10 the function is 1 when C = 0 and 0 when C = 1. What goes on data input 2?

Check

A 4-input priority encoder (I3 highest) outputs a 2-bit code Y1Y0. Write Y0.

Write AND as · or & (or just AB), OR as +, XOR as ⊕, and NOT as ¬ or a trailing ': A·B + C' works.

Check

An n-to-2n decoder with n = 6 is built as a tree of 2-to-4 decoders with enables.

(a)

How many outputs does it have?

(b)

How many 2-to-4 decoders does it need?

Explain why

Why can a multiplexer implement any Boolean function of its select inputs?

Practice

Keep practicing

6 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.