Design all 2-input logic gates using a 2:1 mux.
Design all 2-input logic gates using a 2:1 mux.
Model answer
**Key idea.** A 2:1 multiplexer with select $S$ and data inputs $I_0$, $I_1$ implements Y = \overline{S}\,I_0 + S\,I_1 \qquad (Y=I_0 when S=0,\; Y=I_1 when S=1) Connect input $A$ to the **select** pin and use the other input $B$ (or $\overline{B}$, $0$, $1$) on the data pins. For each value of $A$ we can decide what the output must be, and that is exactly one half of a truth table. **Step 1: split the truth table on $A$.** Read the output when $A=0$ (this goes to $I_0$) and when $A=1$ (this goes to $I_1$). {|c|c|c|c|}\hline Gate & I_0 \;(A=0) & I_1 \;(A=1) & Y \\ \hline AND & 0 & B & A\cdot B \\ \hline OR & B & 1 & A+B \\ \hline NAND & 1 & \overline{B} & \overline{A\cdot B} \\ \hline NOR & \overline{B} & 0 & \overline{A+B} \\ \hline XOR & B & \overline{B} & A\oplus B \\ \hline XNOR & \overline{B} & B & \overline{A\oplus B} \\ \hline **Step 2: check two of them with the mux equation.** AND: Y=\overline{A}\cdot 0 + A\cdot B = AB \qquad\qquad XOR: Y=\overline{A}\,B + A\,\overline{B} = A\oplus B **Single-input gates.** NOT: $I_0=1,\ I_1=0$ with $S=A$ gives $Y=\overline{A}$. Buffer: $I_0=0,\ I_1=1$ gives $Y=A$. **Where does $\overline{B}$ come from?** From one more 2:1 mux used as an inverter ($S=B$, $I_0=1$, $I_1=0$). So the 2:1 mux alone can build every gate, which means it is a **universal** element. **Step 3: the circuits** (top input is $I_0$, bottom input is $I_1$, select $S=A$ at the bottom of each mux): \node[muxdemux, muxdemux def={Lh=1.8, NL=2, Rh=1, NR=1, NB=1, w=1.2}] (M0) at (0.0,0.0) {}; \node[right, xshift=2pt] at (M0.lpin 1) {\ensuremath{I_0}}; \node[right, xshift=2pt] at (M0.lpin 2) {\ensuremath{I_1}}; \draw (M0.lpin 1) -- ++(-0.6,0) node[left]{\ensuremath{0}}; \draw (M0.lpin 2) -- ++(-0.6,0) node[left]{\ensuremath{B}}; \draw (M0.rpin 1) -- ++(0.6,0) node[right]{\ensuremath{Y=A\cdot B}}; \draw (M0.bpin 1) -- ++(0,-0.5) node[below]{\ensuremath{A}}; \node at (0.0,1.35) {AND}; \node[muxdemux, muxdemux def={Lh=1.8, NL=2, Rh=1, NR=1, NB=1, w=1.2}] (M1) at (6.4,0.0) {}; \node[right, xshift=2pt] at (M1.lpin 1) {\ensuremath{I_0}}; \node[right, xshift=2pt] at (M1.lpin 2) {\ensuremath{I_1}}; \draw (M1.lpin 1) -- ++(-0.6,0) node[left]{\ensuremath{B}}; \draw (M1.lpin 2) -- ++(-0.6,0) node[left]{\ensuremath{1}}; \draw (M1.rpin 1) -- ++(0.6,0) node[right]{\ensuremath{Y=A+B}}; \draw (M1.bpin 1) -- ++(0,-0.5) node[below]{\ensuremath{A}}; \node at (6.4,1.35) {OR}; \node[muxdemux, muxdemux def={Lh=1.8, NL=2, Rh=1, NR=1, NB=1, w=1.2}] (M2) at (0.0,-3.9) {}; \node[right, xshift=2pt] at (M2.lpin 1) {\ensuremath{I_0}}; \node[right, xshift=2pt] at (M2.lpin 2) {\ensuremath{I_1}}; \draw (M2.lpin 1) -- ++(-0.6,0) node[left]{\ensuremath{1}}; \draw (M2.lpin 2) -- ++(-0.6,0) node[left]{\ensuremath{\overline{B}}}; \draw (M2.rpin 1) -- ++(0.6,0) node[right]{\ensuremath{Y=\overline{A\cdot B}}}; \draw (M2.bpin 1) -- ++(0,-0.5) node[below]{\ensuremath{A}}; \node at (0.0,-2.55) {NAND}; \node[muxdemux, muxdemux def={Lh=1.8, NL=2, Rh=1, NR=1, NB=1, w=1.2}] (M3) at (6.4,-3.9) {}; \node[right, xshift=2pt] at (M3.lpin 1) {\ensuremath{I_0}}; \node[right, xshift=2pt] at (M3.lpin 2) {\ensuremath{I_1}}; \draw (M3.lpin 1) -- ++(-0.6,0) node[left]{\ensuremath{\overline{B}}}; \draw (M3.lpin 2) -- ++(-0.6,0) node[left]{\ensuremath{0}}; \draw (M3.rpin 1) -- ++(0.6,0) node[right]{\ensuremath{Y=\overline{A+B}}}; \draw (M3.bpin 1) -- ++(0,-0.5) node[below]{\ensuremath{A}}; \node at (6.4,-2.55) {NOR}; \node[muxdemux, muxdemux def={Lh=1.8, NL=2, Rh=1, NR=1, NB=1, w=1.2}] (M4) at (0.0,-7.8) {}; \node[right, xshift=2pt] at (M4.lpin 1) {\ensuremath{I_0}}; \node[right, xshift=2pt] at (M4.lpin 2) {\ensuremath{I_1}}; \draw (M4.lpin 1) -- ++(-0.6,0) node[left]{\ensuremath{B}}; \draw (M4.lpin 2) -- ++(-0.6,0) node[left]{\ensuremath{\overline{B}}}; \draw (M4.rpin 1) -- ++(0.6,0) node[right]{\ensuremath{Y=A\oplus B}}; \draw (M4.bpin 1) -- ++(0,-0.5) node[below]{\ensuremath{A}}; \node at (0.0,-6.449999999999999) {XOR}; \node[muxdemux, muxdemux def={Lh=1.8, NL=2, Rh=1, NR=1, NB=1, w=1.2}] (M5) at (6.4,-7.8) {}; \node[right, xshift=2pt] at (M5.lpin 1) {\ensuremath{I_0}}; \node[right, xshift=2pt] at (M5.lpin 2) {\ensuremath{I_1}}; \draw (M5.lpin 1) -- ++(-0.6,0) node[left]{\ensuremath{\overline{B}}}; \draw (M5.lpin 2) -- ++(-0.6,0) node[left]{\ensuremath{B}}; \draw (M5.rpin 1) -- ++(0.6,0) node[right]{\ensuremath{Y=\overline{A\oplus B}}}; \draw (M5.bpin 1) -- ++(0,-0.5) node[below]{\ensuremath{A}}; \node at (6.4,-6.449999999999999) {XNOR}; **Verilog (verified in simulation, all 4 input combinations correct).**