Boolean Circuits · NAND Game: Memory (Optional)
Lesson 7
You are now able to store a \(16\)-bit word in a register. Additional memory capacity can be obtained simply by stacking such registers. However, since a processor operates on one word at a time, it is necessary to provide a mechanism for selecting and modifying individual words within a larger memory bank. This objective is achieved through the use of memory addresses. Each word in memory is assigned a numerical address, thereby enabling the retrieval or overwriting of a word by specifying its corresponding number. In this task, you are required to employ two registers and to address them using a single-bit address signal.
Problem. Construct a RAM with two 16-bit registers. The three input bits are \(\texttt{ad}\), \(\texttt{st}\), and \(\texttt{cl}\). The label \(\texttt{x}\) is a hardcoded 16-bit input, so you may use it directly in gate lines. The output of your circuit must be a single 16-bit label.
The address bit \(\texttt{ad}\) selects which register is accessed: \[\begin{array}{c | l} ad & \text{selected register} \\ \hline 0 & \text{register } 0 \\ 1 & \text{register } 1\end{array}\]
Both registers initially store \(0\). Your circuit will be tested on many sequences of inputs \(\texttt{(ad,st,x,cl)}\). The behavior is as follows:
- if \(\texttt{st}\)=1, then the current value of \(\texttt{x}\) is written to the addressed register;
- if \(\texttt{st}\)=0, then \(\texttt{x}\) is ignored;
- the write is stored when \(\texttt{cl}\) changes from \(0\) to \(1\), but becomes visible only when \(\texttt{cl}\) changes from \(1\) to \(0\);
- the output is always the value currently stored in the register selected by \(\texttt{ad}\).
You may use only the following functions: \[\begin{aligned}\operatorname{NAND}(a,b) &= \neg(a \land b), \\ \operatorname{INV}(a) &= \neg a, \\ \operatorname{AND}(a,b) &= a \land b, \\ \operatorname{REGISTER}(st,x,cl) &= \text{the current output of a 16-bit register}, \\ \operatorname{SWITCH}(s,d) &= \bigl((s \land d),(\neg s \land d)\bigr), \\ \operatorname{SELECT}_{16}(s,d_1,d_0) &= \begin{cases} d_0, & s=0, \\ d_1, & s=1. \end{cases}\end{aligned}\] For example, a line \(\texttt{w1 w0 ad st SWITCH}\) means that \(\texttt{w1}\)=1 exactly when \(\texttt{ad}\)=1 and \(\texttt{st}\)=1, and \(\texttt{w0}\)=1 exactly when \(\texttt{ad}\)=0 and \(\texttt{st}\)=1.
The authors' solution uses \(4\) gates.