2020-06-15 21:50:29 +00:00
|
|
|
# nand2tetris ![Status Badge](https://img.shields.io/badge/status-in%20progress-red)
|
2020-05-19 12:02:15 +00:00
|
|
|
|
2020-05-19 14:06:41 +00:00
|
|
|
Working my way through the [Nand to Tetris Course](https://www.nand2tetris.org/)
|
|
|
|
|
2020-05-19 12:42:52 +00:00
|
|
|
- Download the latest `nand2tetris.zip` from the book website, and overwrite everything in the `projects` and `tools` directory.
|
|
|
|
- Remember to run `chmod +X tools/*.sh` if you're on \*nix.
|
2020-05-19 14:03:19 +00:00
|
|
|
|
2020-06-15 21:50:29 +00:00
|
|
|
## High level implementation notes
|
|
|
|
|
|
|
|
1. Projects 1-5 as is
|
|
|
|
2. Project 6 (Assembler) done in ruby with a port to Rust in progress
|
|
|
|
3. Project 7-8 (VM) done in PHP
|
|
|
|
4. Project 9 - Wrote a small 2 player Tic Tac Toe game. Plan to upgrade it to Ultimate Tic Tac Toe when I get time.
|
|
|
|
5. Project 10-11 - Writing the compiler in Python
|
|
|
|
|
|
|
|
Detailed notes documenting progress updates are in [NOTES.md](NOTES.md).
|
2020-05-28 20:30:59 +00:00
|
|
|
|
2020-05-19 14:03:19 +00:00
|
|
|
## [Project 1: Boolean Logic](https://www.nand2tetris.org/project01)
|
|
|
|
|
|
|
|
Build order as per the website. Cost for each gate in NAND in brackets.
|
|
|
|
|
|
|
|
- [x] `Nand` (primitive)
|
|
|
|
- [x] `Not` (1)
|
|
|
|
- [x] `Or` (3)
|
2020-05-19 16:52:53 +00:00
|
|
|
- [x] `Xor` (6, Can be improved)
|
2020-05-19 14:03:19 +00:00
|
|
|
- [x] `And` (2)
|
2020-05-19 16:52:53 +00:00
|
|
|
- [x] `Mux` (8, Took me ages. Can be improved)
|
2020-05-19 14:03:19 +00:00
|
|
|
- [x] `DMux` (5, Super Fun)
|
|
|
|
- [x] `Not16` (16)
|
|
|
|
- [x] `And16` (32)
|
|
|
|
- [x] `Or16` (48)
|
2020-05-19 16:52:53 +00:00
|
|
|
- [x] `Mux16` (113)
|
2020-05-19 17:22:09 +00:00
|
|
|
- [x] `Or8Way` (21)
|
2020-05-19 20:32:46 +00:00
|
|
|
- [x] `Mux4Way16` (339)
|
|
|
|
- [x] `Mux8Way16` (791)
|
2020-05-20 09:07:46 +00:00
|
|
|
- [x] `DMux4Way` (37, Fun)
|
2020-05-20 09:16:51 +00:00
|
|
|
- [x] `DMux8Way` (101)
|
2020-05-20 11:18:14 +00:00
|
|
|
|
|
|
|
## [Project 2: Boolean Arithmetic](https://www.nand2tetris.org/project02)
|
|
|
|
|
2020-05-20 20:29:59 +00:00
|
|
|
CHIPs/Gates used in brackets
|
|
|
|
|
|
|
|
- [x] `HalfAdder` (Xor+And)
|
|
|
|
- [x] `FullAdder` (2 HalfAdder, 1 Or)
|
|
|
|
- [x] `Add16` (1 HalfAdder, 15 FullAdder)
|
|
|
|
- [x] `Inc16` (1 Add16)
|
|
|
|
- [x] `ALU` (6 Mux16, 3 Not16, 1 Add16, 1 And16, 2 Or8Way, 2 Or, 1 Not)
|
2020-05-20 13:19:00 +00:00
|
|
|
|
|
|
|
## [Project 3: Memory](https://www.nand2tetris.org/project03)
|
|
|
|
|
2020-05-20 20:29:59 +00:00
|
|
|
Make sure you read through the [Hardware Simulator Tutorial][s] to understand the clock in the simulator.
|
2020-05-20 13:19:00 +00:00
|
|
|
|
2020-05-20 19:36:50 +00:00
|
|
|
- [x] `DFF` (primitive)
|
|
|
|
- [x] `Bit` (1 Mux, 1DFF)
|
|
|
|
- [x] `Register` (16 Bits)
|
2020-05-28 09:34:07 +00:00
|
|
|
- [x] `RAM8` (8 Registers, 1 DMux8Way, 1 Mux8Way16) = 8 registers
|
|
|
|
- [x] `RAM64` (8 RAM8, 1 DMux8Way, 1 Mux8Way16) = 64 registers
|
|
|
|
- [x] `RAM512` (8 RAM64, 1 DMux8Way, 1 Mux8Way16) = 512 registers
|
|
|
|
- [x] `RAM4K` (8 RAM512, 1 DMux8Way, 1 Mux8Way16) = 4096 registers
|
|
|
|
- [x] `RAM16K` (4 RAM4K, 1 DMux4Way, 1 Mux4Way16) = 16384 registers
|
2020-05-20 19:36:50 +00:00
|
|
|
- [x] `PC` (1 Register, 1 Inc16, 1 Or8Way, 1 Mux8Way16)
|
|
|
|
|
2020-05-20 20:29:59 +00:00
|
|
|
[s]: https://b1391bd6-da3d-477d-8c01-38cdf774495a.filesusr.com/ugd/44046b_bfd91435260748439493a60a8044ade6.pdf
|
2020-05-28 09:34:07 +00:00
|
|
|
|
2020-05-28 11:32:13 +00:00
|
|
|
## [Project 4: Machine Language Programming](https://www.nand2tetris.org/project03)
|
2020-05-28 09:34:07 +00:00
|
|
|
|
2020-05-28 11:18:24 +00:00
|
|
|
Counting number of instructions by `wc -l $file.hack`
|
2020-05-28 09:34:07 +00:00
|
|
|
|
|
|
|
- [x] Mult (18)
|
2020-05-28 11:18:24 +00:00
|
|
|
- [x] Fill (98)
|
2020-05-28 11:32:13 +00:00
|
|
|
|
|
|
|
## [Project 5: Computer Architecture](https://www.nand2tetris.org/project05)
|
|
|
|
|
2020-05-28 16:14:21 +00:00
|
|
|
### Chips
|
|
|
|
|
2020-05-28 15:43:25 +00:00
|
|
|
- [x] `Memory.hdl` (2xMux16, 2xNot, 3xAnd 1 RAM16K)
|
|
|
|
- [x] `CPU.hdl` (6 And, 2 Nand, 3 Or, 1 Not, 1 Mux16, 1 Mux16, 2 Register, 1 PC, 1 ALU)
|
2020-05-28 15:58:20 +00:00
|
|
|
- [x] `Computer.hdl` (1 CPU, 1 ROM32K, 1 Memory)
|
2020-05-28 11:32:13 +00:00
|
|
|
|
2020-05-28 16:14:21 +00:00
|
|
|
### Computer chip tests:
|
2020-05-28 11:32:13 +00:00
|
|
|
|
2020-05-28 15:58:20 +00:00
|
|
|
- [x] `Add.hack`
|
|
|
|
- [x] `Max.hack`
|
|
|
|
- [x] `Rect.hack`
|
2020-05-28 16:14:21 +00:00
|
|
|
|
|
|
|
## [Project 6: The Assembler](https://www.nand2tetris.org/project06)
|
|
|
|
|
|
|
|
### Without Symbols
|
|
|
|
|
2020-05-29 20:02:31 +00:00
|
|
|
- [x] `MaxL.asm`
|
|
|
|
- [x] `RectL.asm`
|
|
|
|
- [x] `PongL.asm`
|
|
|
|
- [x] `Add.asm`
|
2020-05-28 16:14:21 +00:00
|
|
|
|
|
|
|
### Symbolic Programs
|
|
|
|
|
2020-05-29 20:41:31 +00:00
|
|
|
- [x] `Max.asm`
|
|
|
|
- [x] `Rect.asm`
|
|
|
|
- [x] `Pong.asm`
|
2020-05-30 22:01:27 +00:00
|
|
|
|
2020-06-04 10:17:23 +00:00
|
|
|
## [Project 7: Virtual Machine I - Stack Arithmetic](https://www.nand2tetris.org/project07)
|
2020-05-30 22:01:27 +00:00
|
|
|
|
2020-06-01 18:40:15 +00:00
|
|
|
Final hack instruction set count in brackets. Calculated by running:
|
|
|
|
|
2020-06-08 19:38:36 +00:00
|
|
|
```bash
|
2020-06-01 18:40:15 +00:00
|
|
|
php file.vm > file.asm
|
|
|
|
ruby assembler.rb file.vm > file.hack
|
|
|
|
wc -l file.hack
|
|
|
|
```
|
|
|
|
|
2020-05-30 22:01:27 +00:00
|
|
|
### Arithmetic Commands
|
|
|
|
|
2020-06-03 12:19:21 +00:00
|
|
|
- [x] `SimpleAdd.vm` (21)
|
|
|
|
- [x] `StackTest.vm` (334)
|
2020-05-30 22:01:27 +00:00
|
|
|
|
|
|
|
### Memory Access Commands
|
|
|
|
|
2020-06-03 12:19:21 +00:00
|
|
|
- [x] `BasicTest.vm` (228)
|
|
|
|
- [x] `PointerTest.vm` (127)
|
|
|
|
- [x] `StackTest.vm` (73)
|
|
|
|
|
2020-06-04 10:17:23 +00:00
|
|
|
## [Project 8: Virtual Machine II - Program Control](https://www.nand2tetris.org/project08)
|
2020-06-03 12:19:21 +00:00
|
|
|
|
2020-06-08 19:38:36 +00:00
|
|
|
Final hack instruction set count in brackets as before.
|
|
|
|
|
2020-06-03 12:19:21 +00:00
|
|
|
### Program Flow Commands
|
|
|
|
|
2020-06-03 12:59:50 +00:00
|
|
|
- [x] `BasicLoop.vm` (93)
|
2020-06-03 13:36:04 +00:00
|
|
|
- [x] `Fibonacci.vm` (193)
|
2020-06-03 12:19:21 +00:00
|
|
|
|
|
|
|
## Function Calling Commands
|
|
|
|
|
2020-06-03 19:18:54 +00:00
|
|
|
- [x] `SimpleFunction.vm` (128)
|
2020-06-04 15:35:02 +00:00
|
|
|
- [x] `FibonacciElement` (434)
|
|
|
|
- [x] `NestedCall.vm` (556)
|
|
|
|
- [x] `StaticsTest.vm` (664)
|
2020-06-08 19:38:36 +00:00
|
|
|
|
|
|
|
## [Project 9: High-Level Programming](https://www.nand2tetris.org/project09)
|
2020-06-09 21:05:09 +00:00
|
|
|
|
|
|
|
- [x] TicTacToe
|
|
|
|
|
|
|
|
## [Project 10: Compiler I - Syntax Analysis](https://www.nand2tetris.org/project10)
|
|
|
|
|
|
|
|
### Tokenizer
|
|
|
|
|
2020-06-15 20:46:37 +00:00
|
|
|
- [x] Square
|
|
|
|
- [x] TestArray
|
2020-06-09 21:05:09 +00:00
|
|
|
|
|
|
|
### Parser (Compilation Engine)
|
|
|
|
|
|
|
|
- [ ] Square
|
|
|
|
- [ ] ExpressionLessSquare
|
|
|
|
- [ ] TestArray
|