Building own Computer with Nand2Tetris: Project II
Gökhan Koçmarlı -
This week's project includes creating an adder circuit, an increment circuit, and combining all the things into an arithmetic logic unit that we have created so far.
The ones whose interested in with Nand2Tetris-HDL, please check the manual.
From the truth table, we can easily recognize that $\text{sum} = A \oplus B$ and $\text{carry} = AB$ for inputs A and B. Creation of such circuit will be very easy for us in HDL.
Full Adder
Half adder can only add two bits, and give us the sum and the carry. To create a circuit which can add more than one bit, we will need a three-input adder circuit, since we also need to add previous carry.
Think about this: 28 + 94. Adding of less significant character (8 and 4) can be done with half adder. It'll give us a sum of 2, and a carry of 1. To add second characters, we have to add three different numbers now: 2 + 9 + 1 (carry). That's the reason we require full adder.
A full adder can be implemented using two half adders, and a OR gate for combination of carries.
It is time to create a 16-bit adder, then!
16-bit Adder
Incrementer
The line you see on the Add16 part written as b[0]=true means that make the input's first bit equal to 1, and we are sure b will be a 16-bit value because of the implementation of it.
Arithmetic Logic Unit
In the course, we are asked to implement a ALU which can do these functions within given inputs:
Here's the HDL I have created.
The file also calls for two chips that we haven't introduced before. I have created them because the Nand2Tetris-HDL does not allow us to use an internal pin's sub-bits-array. Therefore, I used a method to avoid "internal pin" behavior. You can see these chips' HDL files below.