Building a Modern Computer - Project 2 Review

Written politely 2021-06-29.

This week’s project was building 5 chip designs, the HalfAdder, FullAdder, Add16, Inc16, and two version the the ALU, the Arithmetic Logic Unit. If you missed the overview of this project, please read through that first. If you need to start at the beginning, that is always a great place to begin.

Half Adder

half adder

The half adder takes two bits as inputs, adds them together and outputs two bits as the output. The book basically explained this one and if you look closely at the compare table, you will see that the sum and carry outputs match the behavior of two chips from Project 1. Think about this as a simple binary addition problem like this:

1 + 0 = 01, or 0 + 0 = 00, or 1 + 1 = 11 with the addends being the inputs an the output being a two bit sum.

Full Adder

full adder

The full added allows a third input to be involved, representing a carry bit from a previous adding column. Imagine using it when there is a carry from the previous column to make sure the carry is not lost in your binary addition. Look at the second column in this problem (the column to the left). Notice that after adding the first column we have a carry to the second column of 1. The full adder covers this case in adding two bits plus a carry bit.

01 + 11 = 100

16-bit Adder

multi-bit adder

The 16-bit adder makes it possible to have two 16-bit inputs that are added together into one 16-bit output, with the most significant carry bit (if it is a 1) being ignored (else it would be a 17-bit output). It should be obvious how to use previous chips to construct the internal chip logic for this one as we have done the preliminary work already. But it would represent something such as this:

0110010111011100 + 1011110011011101 = (1)0010001010111001

16-bit Incrementer

16-bit incrementer

The 16-bit incrementer, or Add16, takes one input, adds 1 to the number, and outputs the result, which is also a 16-bit number. We also drop the last carry value to keep the output as a 16-bit number, such as in this example which would exceed the word size:

1111111111111111 + 0000000000000001 = (1)0000000000000000

One of the tricks with the syntax that I needed to look up to figure this one out is being able to reference different bits of output with true/false boolean values that represent 1/0 respectively. For instance, if I wanted to represent the most significant bit of the second addend, I could represent it like so in the hdl chip output:

b[15] = false

That was the only tricky part that I found that should save you from having to look up the syntax to and accidentally seeing a solved problem. Sometimes we know what and how we want to solve a problem, but the language syntax holds us back from actually finishing the problem. The above representation of a single bit as a boolean should clear up any syntax difficulties with finishing this one.

ALU Without Handling of Status Outputs

hack-chip

The ALU was the chip that took the most time to complete in this second project, in my opinion. It was split into two parts, this being the first. The ALU has two 16-bit inputs, x and y, and 7 functional one-bit switches.

The first, zx, will take the x input and output x as 0 if true and x if false. The second, nx, will negate the output of zx if true.

There are two more of the same corresponding functions for y. zy will zero the y input and ny will negate the y input.

An f will compute x + y if true else x & y.

The last function is no, which will negate the final output.

The final output is the result of the value of the two inputs with the actions for all 6 bits to a single 16-bit output.

zx -> nx -> zy -> ny -> f -> no

ALU Complete adds two more single-bit outputs

The second half of the ALU assignment was given to two final output bits.

zr returns 1 if the output of the above is 0 (out == 0). Otherwise, it returns false.

ng returns 1 if the output of the above is less than 0 (out < 0). Otherwise it returns false.

control bits

Summary

The ALU took the most time to complete, but getting there was a thought provoking exercise. Seeing our initial nand chip be the building blocks for these more complex chips is great to reflect. We just built a basic arithmetic logic chip. Congratulations!

The next unit is about Memory.

Yesterday was the hottest day in Seattle’s recorded history. That was exhausting, tbh. I am taking a little holiday to go make some memories with my family and the code behind them.

Also, happy early anniversary to the love of my life, Dr. J! Our 14th wedding Anniversary is tomorrow. 👫 You are the best! 🎳 Calmer than you are. 🎳

Today’s mental trinket is brought to you by:

Stay Fresh Cheese Bags


Lucas McDaniel

Husband, father, teacher, musician, avid gamer, nature enthusiast, and passionate about the human condition.