Boolean Circuits · NAND Game: Arithmetic and Switching
Lesson 6
Problem. Construct a component that outputs \(A-B\) as an 8-bit number. The inputs are \(a_{7},a_{6},\dotsc,a_{0},b_{7},b_{6},\dotsc,b_{0}\), where \(a_{7}\) and \(b_{7}\) are the most significant bits. The outputs are \(y_{7},y_{6},\dotsc,y_{0}\), where \(y_{7}\) is the most significant bit of the result.
If the result is negative, represent it as \(256+(A-B)\). This is equivalent to two's complement representation modulo \(2^{8}\).
You may use only the following functions: \[\begin{aligned}\operatorname{NAND}(a,b) &= \neg(a \land b), & \operatorname{INV}(a) &= \neg a, \\ 0() &= 0, & \operatorname{OR}(a,b) &= a \lor b, \\ \operatorname{INC}_{8}(a_7,\dotsc,a_0) &= (s_7,\dotsc,s_0), \\ \operatorname{ADD}_{8}(a_7,\dotsc,a_0,b_7,\dotsc,b_0,c) &= (u,s_7,\dotsc,s_0), \\ \operatorname{INV}_{8}(a_7,\dotsc,a_0) &= (\overline{a_7},\dotsc,\overline{a_0}).\end{aligned}\] Where the line of code \(\texttt{x 0}\) assigns the value \(0\) to the variable \(\texttt{x}\).
Examples: \[\begin{array}{r|c|r} \text{result} & 8\text{-bit binary} & \text{unsigned decimal} \\ \hline 1 & 00000001 & 1 \\ 0 & 00000000 & 0 \\ -1 & 11111111 & 255 \\ -2 & 11111110 & 254 \\ -3 & 11111101 & 253\end{array}\]
The authors' solution uses \(4\) gates.