Daily Learning Notes for February 2, 2016

Time for more NAND2Tetris! I’m still feeling a bit sleep-deprived but not as bad as yesterday, so maybe I have a chance of finishing this CPU! Yesterday I made sure I understood the specifications, and today I’ll try to complete my design.

Finishing the CPU

I think I’m finally ready to start sketching out some ideas, and then I’ll build my chip by writing it up in the hardware description language (HDL) and testing it in the hardware simulator.

I think I understand how all the pieces fit together: the arithmetic logic unit (ALU), the two registers, and the program counter. I understand how the instruction input will decide what operations the ALU should run or what address should be stored. I understand how the program counter works. Time to draw it!

A while later: I have a very messy sketch but it does the job! I compared it to the diagram provided in the book and it looks like I got it right! Yay! The only piece missing now is the rest of the logic for control what happens when, based on the instruction input. The diagram in the book leaves that part out, too. (My design was probably informed by glancing at that diagram when I read the chapter the other day, but I made a point of not looking at it for too long so I could try to figure it out for myself. I’m very pleased to see that I was able to do it without referencing their hints!)

OK, so, logic… I think I realized the key piece that I was missing yesterday: I can’t just pass individual bits from the instruction input directly into the ALU. I need to do some AND-ing together first and then use the generated outputs as the control bits for the ALU.

A short while later: Done! I wrote it up in HDL, but it isn’t working. I had a feeling it wouldn’t, because I feel like I have no clue what I’m doing! First I had an error because I accidentally switched two inputs in my HDL. Fixed that. But now I’m not getting an address output when I should be…

Oops! I had my bits flipped. OK, that should work… Oh no! Another error! What is it this time…

Oh, I forgot to fan out one of the ouputs. OK, easy fix. Let’s try it again, fingers crossed…

End of script - Comparison ended successfully

Woot!!! I have a working CPU! Oh wow, that was easier than I thought! OK, let’s finish up this project then.

Building the final computer

This last part is going to be a piece of cake! All I have to do is connect the CPU I just built with the final data memory chip I built yesterday and the prebuilt ROM. Just gotta figure out which outputs go to which inputs…

The ROM takes one input and gives one output. It contains the instructions for a given program. The data memory chip contains the RAM and screen and keyboard chips. The CPU handles the operations.

OK, so the CPU should definitely get its instruction input from the ROM, its reset input from the user, and its data input from the data memory.

The data memory should probably get its data input from the CPU’s data output, its address input from the CPU’s address output, and its load input from the CPU’s “writeM” output.

Finally, the instruction memory or ROM should get its input from the CPU’s program counter output to determine which instructions to fetch next.

Now I’ll just write that up in HDL and test it in the hardware simulator with the provided Hack computer programs and see if it works!

Once again, fingers crossed…

End of script - Comparison ended successfully

Woohoo!!! I have a working computer!!! It passes all the test scripts. Wow, that was easier than I thought! I’m almost a bit disappointed that it wasn’t more difficult!

Well, now’s a good time to call it a night.

Learning summary (#TIL)

  • I finished building the CPU and the final computer, and it actually works!

Next steps

  • Begin week 6 of NAND2Tetris and start planning how I might want to teach this material or start a study group.

Time breakdown

  • Study time: 1 hour 42 min
    • Week 5 project: 1 hour 42 min