├── .Rhistory
├── Hack-Computer-description-in-HDL
├── 5. Hack Computer
│ ├── Computer
│ │ ├── rect-test
│ │ │ ├── ComputerRect.out
│ │ │ ├── Rect.hack
│ │ │ ├── ComputerRect-external.out
│ │ │ ├── ComputerRect-external.cmp
│ │ │ ├── ComputerRect-external.tst
│ │ │ ├── ComputerRect.tst
│ │ │ └── ComputerRect.cmp
│ │ ├── add-test
│ │ │ ├── Add.hack
│ │ │ ├── ComputerAdd-external.out
│ │ │ ├── ComputerAdd-external.cmp
│ │ │ ├── ComputerAdd-external.tst
│ │ │ ├── ComputerAdd.tst
│ │ │ ├── ComputerAdd.out
│ │ │ └── ComputerAdd.cmp
│ │ ├── max-test
│ │ │ ├── Max.hack
│ │ │ ├── ComputerMax-external.tst
│ │ │ ├── ComputerMax.tst
│ │ │ ├── ComputerMax-external.out
│ │ │ ├── ComputerMax-external.cmp
│ │ │ └── ComputerMax.cmp
│ │ └── Computer.hdl
│ ├── Data Memory
│ │ ├── Memory.hdl
│ │ ├── Memory.out
│ │ ├── Memory.cmp
│ │ └── Memory.tst
│ └── CPU
│ │ ├── CPU.hdl
│ │ ├── CPU.tst
│ │ ├── CPU-external.tst
│ │ ├── CPU-external.out
│ │ ├── CPU-external.cmp
│ │ ├── CPU.out
│ │ └── CPU.cmp
├── 1. Elementary chipset (combinational chips)
│ ├── elementary gates
│ │ ├── 2. AND
│ │ │ ├── And.out
│ │ │ ├── And.cmp
│ │ │ ├── And.hdl
│ │ │ └── And.tst
│ │ ├── 1. NOT
│ │ │ ├── Not.cmp
│ │ │ ├── Not.out
│ │ │ ├── Not.hdl
│ │ │ └── Not.tst
│ │ ├── 3. OR
│ │ │ ├── Or.out
│ │ │ ├── Or.cmp
│ │ │ ├── Or.hdl
│ │ │ └── Or.tst
│ │ ├── 4. XOR
│ │ │ ├── Xor.out
│ │ │ ├── Xor.cmp
│ │ │ ├── Xor.tst
│ │ │ └── Xor.hdl
│ │ ├── 6.DMUX
│ │ │ ├── DMux.out
│ │ │ ├── DMux.cmp
│ │ │ ├── DMux.hdl
│ │ │ └── DMux.tst
│ │ └── 5. MUX
│ │ │ ├── Mux.out
│ │ │ ├── Mux.cmp
│ │ │ ├── Mux.hdl
│ │ │ └── Mux.tst
│ ├── multi-way variants
│ │ ├── 1. Or8Way
│ │ │ ├── Or8Way.out
│ │ │ ├── Or8Way.cmp
│ │ │ ├── Or8Way.tst
│ │ │ └── Or8Way.hdl
│ │ ├── 4.DMux4Way
│ │ │ ├── DMux4Way.out
│ │ │ ├── DMux4Way.cmp
│ │ │ ├── DMux4Way.tst
│ │ │ └── DMux4Way.hdl
│ │ ├── 2. MUX4Way16
│ │ │ ├── Mux4Way16.hdl
│ │ │ ├── Mux4Way16.tst
│ │ │ ├── Mux4Way16.out
│ │ │ └── Mux4Way16.cmp
│ │ ├── 3. Mux8Way16
│ │ │ ├── Mux8Way16.hdl
│ │ │ ├── Mux8Way16.tst
│ │ │ ├── Mux8Way16.out
│ │ │ └── Mux8Way16.cmp
│ │ └── 5.DMux8Way
│ │ │ ├── DMux8Way.out
│ │ │ ├── DMux8Way.cmp
│ │ │ ├── DMux8Way.hdl
│ │ │ └── DMux8Way.tst
│ └── 16-bit variants
│ │ ├── 1. NOT16
│ │ ├── Not16.out
│ │ ├── Not16.cmp
│ │ ├── Not16.tst
│ │ └── Not16.hdl
│ │ ├── 2. AND16
│ │ ├── And16.out
│ │ ├── And16.cmp
│ │ ├── And16.tst
│ │ └── And16.hdl
│ │ ├── 3. OR16
│ │ ├── Or16.out
│ │ ├── Or16.cmp
│ │ ├── Or16.tst
│ │ └── Or16.hdl
│ │ └── 4. MUX16
│ │ ├── Mux16.out
│ │ ├── Mux16.cmp
│ │ ├── Mux16.tst
│ │ └── Mux16.hdl
├── 2. Adders and ALU (combinational chips)
│ ├── Adders
│ │ ├── 1. HalfAdder
│ │ │ ├── HalfAdder.out
│ │ │ ├── HalfAdder.cmp
│ │ │ ├── HalfAdder.hdl
│ │ │ └── HalfAdder.tst
│ │ ├── 4. 16-bit Incrementer
│ │ │ ├── Inc16.out
│ │ │ ├── Inc16.cmp
│ │ │ ├── Inc16.hdl
│ │ │ └── Inc16.tst
│ │ ├── 2. FullAdder
│ │ │ ├── FullAdder.out
│ │ │ ├── FullAdder.cmp
│ │ │ ├── FullAdder.hdl
│ │ │ └── FullAdder.tst
│ │ └── 3. 16-bit Adder
│ │ │ ├── Add16.out
│ │ │ ├── Add16.cmp
│ │ │ ├── Add16.tst
│ │ │ └── Add16.hdl
│ └── ALU
│ │ ├── ALU.hdl
│ │ ├── ALU.out
│ │ ├── ALU.cmp
│ │ └── ALU.tst
├── 4. Hack Assembly Programming
│ ├── mult
│ │ ├── Mult.out
│ │ ├── Mult.cmp
│ │ ├── Mult.hack
│ │ ├── mult.asm
│ │ └── Mult.tst
│ └── fill
│ │ ├── Fill.tst
│ │ ├── FillAutomatic.cmp
│ │ ├── FillAutomatic.out
│ │ ├── Fill.hack
│ │ ├── FillAutomatic.tst
│ │ └── Fill.asm
└── 3. Memory units and PC (sequential chips)
│ ├── Registers
│ ├── Bit.hdl
│ ├── Register.hdl
│ ├── Register.out
│ ├── Register.cmp
│ ├── Bit.out
│ └── Bit.cmp
│ ├── Program Counter
│ ├── PC.hdl
│ ├── PC.out
│ └── PC.tst
│ └── RAMn
│ ├── RAM16K.hdl
│ ├── RAM8.hdl
│ ├── RAM64.hdl
│ ├── RAM512.hdl
│ └── RAM4K.hdl
├── Images
├── .png
├── ram.png
├── chip.png
├── logo.png
├── open.png
└── simulate.png
├── Hack-Computer-(Logisim)
└── Images
│ ├── hack-cpu.png
│ ├── hack-ram-64.png
│ ├── hack-ram-8.png
│ └── hack-computer.png
└── README.md
/.Rhistory:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/rect-test/ComputerRect.out:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Images/.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VitorgsRuffo/Building-The-Hack-Computer/HEAD/Images/.png
--------------------------------------------------------------------------------
/Images/ram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VitorgsRuffo/Building-The-Hack-Computer/HEAD/Images/ram.png
--------------------------------------------------------------------------------
/Images/chip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VitorgsRuffo/Building-The-Hack-Computer/HEAD/Images/chip.png
--------------------------------------------------------------------------------
/Images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VitorgsRuffo/Building-The-Hack-Computer/HEAD/Images/logo.png
--------------------------------------------------------------------------------
/Images/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VitorgsRuffo/Building-The-Hack-Computer/HEAD/Images/open.png
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/2. AND/And.out:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Images/simulate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VitorgsRuffo/Building-The-Hack-Computer/HEAD/Images/simulate.png
--------------------------------------------------------------------------------
/Hack-Computer-(Logisim)/Images/hack-cpu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VitorgsRuffo/Building-The-Hack-Computer/HEAD/Hack-Computer-(Logisim)/Images/hack-cpu.png
--------------------------------------------------------------------------------
/Hack-Computer-(Logisim)/Images/hack-ram-64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VitorgsRuffo/Building-The-Hack-Computer/HEAD/Hack-Computer-(Logisim)/Images/hack-ram-64.png
--------------------------------------------------------------------------------
/Hack-Computer-(Logisim)/Images/hack-ram-8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VitorgsRuffo/Building-The-Hack-Computer/HEAD/Hack-Computer-(Logisim)/Images/hack-ram-8.png
--------------------------------------------------------------------------------
/Hack-Computer-(Logisim)/Images/hack-computer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VitorgsRuffo/Building-The-Hack-Computer/HEAD/Hack-Computer-(Logisim)/Images/hack-computer.png
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/1. NOT/Not.cmp:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0 | 1 |
3 | | 1 | 0 |
4 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/1. NOT/Not.out:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0 | 1 |
3 | | 1 | 0 |
4 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/add-test/Add.hack:
--------------------------------------------------------------------------------
1 | 0000000000000010
2 | 1110110000010000
3 | 0000000000000011
4 | 1110000010010000
5 | 0000000000000000
6 | 1110001100001000
7 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/3. OR/Or.out:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0 | 0 | 0 |
3 | | 0 | 1 | 1 |
4 | | 1 | 0 | 1 |
5 | | 1 | 1 | 1 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/3. OR/Or.cmp:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0 | 0 | 0 |
3 | | 0 | 1 | 1 |
4 | | 1 | 0 | 1 |
5 | | 1 | 1 | 1 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/4. XOR/Xor.out:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0 | 0 | 0 |
3 | | 0 | 1 | 1 |
4 | | 1 | 0 | 1 |
5 | | 1 | 1 | 0 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/2. AND/And.cmp:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0 | 0 | 0 |
3 | | 0 | 1 | 0 |
4 | | 1 | 0 | 0 |
5 | | 1 | 1 | 1 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/4. XOR/Xor.cmp:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0 | 0 | 0 |
3 | | 0 | 1 | 1 |
4 | | 1 | 0 | 1 |
5 | | 1 | 1 | 0 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/1. Or8Way/Or8Way.out:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 00000000 | 0 |
3 | | 11111111 | 1 |
4 | | 00010000 | 1 |
5 | | 00000001 | 1 |
6 | | 00100110 | 1 |
7 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/1. Or8Way/Or8Way.cmp:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 00000000 | 0 |
3 | | 11111111 | 1 |
4 | | 00010000 | 1 |
5 | | 00000001 | 1 |
6 | | 00100110 | 1 |
7 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/1. HalfAdder/HalfAdder.out:
--------------------------------------------------------------------------------
1 | | a | b | sum | carry |
2 | | 0 | 0 | 0 | 0 |
3 | | 0 | 1 | 1 | 0 |
4 | | 1 | 0 | 1 | 0 |
5 | | 1 | 1 | 0 | 1 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/6.DMUX/DMux.out:
--------------------------------------------------------------------------------
1 | | in | sel | a | b |
2 | | 0 | 0 | 0 | 0 |
3 | | 0 | 1 | 0 | 0 |
4 | | 1 | 0 | 1 | 0 |
5 | | 1 | 1 | 0 | 1 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/1. HalfAdder/HalfAdder.cmp:
--------------------------------------------------------------------------------
1 | | a | b | sum | carry |
2 | | 0 | 0 | 0 | 0 |
3 | | 0 | 1 | 1 | 0 |
4 | | 1 | 0 | 1 | 0 |
5 | | 1 | 1 | 0 | 1 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/6.DMUX/DMux.cmp:
--------------------------------------------------------------------------------
1 | | in | sel | a | b |
2 | | 0 | 0 | 0 | 0 |
3 | | 0 | 1 | 0 | 0 |
4 | | 1 | 0 | 1 | 0 |
5 | | 1 | 1 | 0 | 1 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/4. 16-bit Incrementer/Inc16.out:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0000000000000000 | 0000000000000001 |
3 | | 1111111111111111 | 0000000000000000 |
4 | | 0000000000000101 | 0000000000000110 |
5 | | 1111111111111011 | 1111111111111100 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/4. 16-bit Incrementer/Inc16.cmp:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0000000000000000 | 0000000000000001 |
3 | | 1111111111111111 | 0000000000000000 |
4 | | 0000000000000101 | 0000000000000110 |
5 | | 1111111111111011 | 1111111111111100 |
6 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/4. Hack Assembly Programming/mult/Mult.out:
--------------------------------------------------------------------------------
1 | | RAM[0] | RAM[1] | RAM[2] |
2 | | 0 | 0 | 0 |
3 | | 1 | 0 | 0 |
4 | | 0 | 2 | 0 |
5 | | 3 | 1 | 3 |
6 | | 2 | 4 | 8 |
7 | | 6 | 7 | 42 |
8 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/4. Hack Assembly Programming/mult/Mult.cmp:
--------------------------------------------------------------------------------
1 | | RAM[0] | RAM[1] | RAM[2] |
2 | | 0 | 0 | 0 |
3 | | 1 | 0 | 0 |
4 | | 0 | 2 | 0 |
5 | | 3 | 1 | 3 |
6 | | 2 | 4 | 8 |
7 | | 6 | 7 | 42 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/1. NOT16/Not16.out:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0000000000000000 | 1111111111111111 |
3 | | 1111111111111111 | 0000000000000000 |
4 | | 1010101010101010 | 0101010101010101 |
5 | | 0011110011000011 | 1100001100111100 |
6 | | 0001001000110100 | 1110110111001011 |
7 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/1. NOT16/Not16.cmp:
--------------------------------------------------------------------------------
1 | | in | out |
2 | | 0000000000000000 | 1111111111111111 |
3 | | 1111111111111111 | 0000000000000000 |
4 | | 1010101010101010 | 0101010101010101 |
5 | | 0011110011000011 | 1100001100111100 |
6 | | 0001001000110100 | 1110110111001011 |
7 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/max-test/Max.hack:
--------------------------------------------------------------------------------
1 | 0000000000000000
2 | 1111110000010000
3 | 0000000000000001
4 | 1111010011010000
5 | 0000000000001010
6 | 1110001100000001
7 | 0000000000000001
8 | 1111110000010000
9 | 0000000000001100
10 | 1110101010000111
11 | 0000000000000000
12 | 1111110000010000
13 | 0000000000000010
14 | 1110001100001000
15 | 0000000000001110
16 | 1110101010000111
17 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/5. MUX/Mux.out:
--------------------------------------------------------------------------------
1 | | a | b | sel | out |
2 | | 0 | 0 | 0 | 0 |
3 | | 0 | 0 | 1 | 0 |
4 | | 0 | 1 | 0 | 0 |
5 | | 0 | 1 | 1 | 1 |
6 | | 1 | 0 | 0 | 1 |
7 | | 1 | 0 | 1 | 0 |
8 | | 1 | 1 | 0 | 1 |
9 | | 1 | 1 | 1 | 1 |
10 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/5. MUX/Mux.cmp:
--------------------------------------------------------------------------------
1 | | a | b | sel | out |
2 | | 0 | 0 | 0 | 0 |
3 | | 0 | 0 | 1 | 0 |
4 | | 0 | 1 | 0 | 0 |
5 | | 0 | 1 | 1 | 1 |
6 | | 1 | 0 | 0 | 1 |
7 | | 1 | 0 | 1 | 0 |
8 | | 1 | 1 | 0 | 1 |
9 | | 1 | 1 | 1 | 1 |
10 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/4. Hack Assembly Programming/fill/Fill.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/04/fill/Fill.tst
5 |
6 | load Fill.hack;
7 | echo "Make sure that 'No Animation' is selected. Then, select the keyboard, press any key for some time, and inspect the screen.";
8 |
9 | repeat {
10 | ticktock;
11 | }
12 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/1. NOT/Not.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Not.hdl
5 |
6 | /**
7 | * Not gate:
8 | * out = not in
9 | */
10 |
11 | CHIP Not {
12 | IN in;
13 | OUT out;
14 |
15 | PARTS:
16 | Nand(a=in, b=in, out=out);
17 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/4. Hack Assembly Programming/fill/FillAutomatic.cmp:
--------------------------------------------------------------------------------
1 | |RAM[16384]|RAM[17648]|RAM[18349]|RAM[19444]|RAM[20771]|RAM[21031]|RAM[22596]|RAM[23754]|RAM[24575]|
2 | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
3 | | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
4 | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
5 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/4. Hack Assembly Programming/fill/FillAutomatic.out:
--------------------------------------------------------------------------------
1 | |RAM[16384]|RAM[17648]|RAM[18349]|RAM[19444]|RAM[20771]|RAM[21031]|RAM[22596]|RAM[23754]|RAM[24575]|
2 | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
3 | | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
4 | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
5 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/4.DMux4Way/DMux4Way.out:
--------------------------------------------------------------------------------
1 | | in | sel | a | b | c | d |
2 | | 0 | 00 | 0 | 0 | 0 | 0 |
3 | | 0 | 01 | 0 | 0 | 0 | 0 |
4 | | 0 | 10 | 0 | 0 | 0 | 0 |
5 | | 0 | 11 | 0 | 0 | 0 | 0 |
6 | | 1 | 00 | 1 | 0 | 0 | 0 |
7 | | 1 | 01 | 0 | 1 | 0 | 0 |
8 | | 1 | 10 | 0 | 0 | 1 | 0 |
9 | | 1 | 11 | 0 | 0 | 0 | 1 |
10 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/1. NOT/Not.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Not.tst
5 |
6 | load Not.hdl,
7 | output-file Not.out,
8 | compare-to Not.cmp,
9 | output-list in%B3.1.3 out%B3.1.3;
10 |
11 | set in 0,
12 | eval,
13 | output;
14 |
15 | set in 1,
16 | eval,
17 | output;
18 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/4.DMux4Way/DMux4Way.cmp:
--------------------------------------------------------------------------------
1 | | in | sel | a | b | c | d |
2 | | 0 | 00 | 0 | 0 | 0 | 0 |
3 | | 0 | 01 | 0 | 0 | 0 | 0 |
4 | | 0 | 10 | 0 | 0 | 0 | 0 |
5 | | 0 | 11 | 0 | 0 | 0 | 0 |
6 | | 1 | 00 | 1 | 0 | 0 | 0 |
7 | | 1 | 01 | 0 | 1 | 0 | 0 |
8 | | 1 | 10 | 0 | 0 | 1 | 0 |
9 | | 1 | 11 | 0 | 0 | 0 | 1 |
10 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/2. FullAdder/FullAdder.out:
--------------------------------------------------------------------------------
1 | | a | b | c | sum | carry |
2 | | 0 | 0 | 0 | 0 | 0 |
3 | | 0 | 0 | 1 | 1 | 0 |
4 | | 0 | 1 | 0 | 1 | 0 |
5 | | 0 | 1 | 1 | 0 | 1 |
6 | | 1 | 0 | 0 | 1 | 0 |
7 | | 1 | 0 | 1 | 0 | 1 |
8 | | 1 | 1 | 0 | 0 | 1 |
9 | | 1 | 1 | 1 | 1 | 1 |
10 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/2. FullAdder/FullAdder.cmp:
--------------------------------------------------------------------------------
1 | | a | b | c | sum | carry |
2 | | 0 | 0 | 0 | 0 | 0 |
3 | | 0 | 0 | 1 | 1 | 0 |
4 | | 0 | 1 | 0 | 1 | 0 |
5 | | 0 | 1 | 1 | 0 | 1 |
6 | | 1 | 0 | 0 | 1 | 0 |
7 | | 1 | 0 | 1 | 0 | 1 |
8 | | 1 | 1 | 0 | 0 | 1 |
9 | | 1 | 1 | 1 | 1 | 1 |
10 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/3. 16-bit Adder/Add16.out:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 |
3 | | 0000000000000000 | 1111111111111111 | 1111111111111111 |
4 | | 1111111111111111 | 1111111111111111 | 1111111111111110 |
5 | | 1010101010101010 | 0101010101010101 | 1111111111111111 |
6 | | 0011110011000011 | 0000111111110000 | 0100110010110011 |
7 | | 0001001000110100 | 1001100001110110 | 1010101010101010 |
8 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/2. AND16/And16.out:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 |
3 | | 0000000000000000 | 1111111111111111 | 0000000000000000 |
4 | | 1111111111111111 | 1111111111111111 | 1111111111111111 |
5 | | 1010101010101010 | 0101010101010101 | 0000000000000000 |
6 | | 0011110011000011 | 0000111111110000 | 0000110011000000 |
7 | | 0001001000110100 | 1001100001110110 | 0001000000110100 |
8 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/3. OR16/Or16.out:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 |
3 | | 0000000000000000 | 1111111111111111 | 1111111111111111 |
4 | | 1111111111111111 | 1111111111111111 | 1111111111111111 |
5 | | 1010101010101010 | 0101010101010101 | 1111111111111111 |
6 | | 0011110011000011 | 0000111111110000 | 0011111111110011 |
7 | | 0001001000110100 | 1001100001110110 | 1001101001110110 |
8 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/3. OR16/Or16.cmp:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 |
3 | | 0000000000000000 | 1111111111111111 | 1111111111111111 |
4 | | 1111111111111111 | 1111111111111111 | 1111111111111111 |
5 | | 1010101010101010 | 0101010101010101 | 1111111111111111 |
6 | | 0011110011000011 | 0000111111110000 | 0011111111110011 |
7 | | 0001001000110100 | 1001100001110110 | 1001101001110110 |
8 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/3. 16-bit Adder/Add16.cmp:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 |
3 | | 0000000000000000 | 1111111111111111 | 1111111111111111 |
4 | | 1111111111111111 | 1111111111111111 | 1111111111111110 |
5 | | 1010101010101010 | 0101010101010101 | 1111111111111111 |
6 | | 0011110011000011 | 0000111111110000 | 0100110010110011 |
7 | | 0001001000110100 | 1001100001110110 | 1010101010101010 |
8 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/2. AND16/And16.cmp:
--------------------------------------------------------------------------------
1 | | a | b | out |
2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 |
3 | | 0000000000000000 | 1111111111111111 | 0000000000000000 |
4 | | 1111111111111111 | 1111111111111111 | 1111111111111111 |
5 | | 1010101010101010 | 0101010101010101 | 0000000000000000 |
6 | | 0011110011000011 | 0000111111110000 | 0000110011000000 |
7 | | 0001001000110100 | 1001100001110110 | 0001000000110100 |
8 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/4. 16-bit Incrementer/Inc16.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/02/Inc16.hdl
5 |
6 | /**
7 | * 16-bit incrementer:
8 | * out = in + 1 (arithmetic addition)
9 | */
10 |
11 | CHIP Inc16 {
12 | IN in[16];
13 | OUT out[16];
14 |
15 | PARTS:
16 | Add16(a=in, b[0]=true, b[1..15]=false, out=out);
17 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/2. AND/And.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/And.hdl
5 |
6 | /**
7 | * And gate:
8 | * out = 1 if (a == 1 and b == 1)
9 | * 0 otherwise
10 | */
11 |
12 | CHIP And {
13 | IN a, b;
14 | OUT out;
15 |
16 | PARTS:
17 | Nand(a=a, b=b, out=aNandb);
18 | Not(in=aNandb, out=out);
19 | }
20 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/3. OR/Or.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Or.hdl
5 |
6 | /**
7 | * Or gate:
8 | * out = 1 if (a == 1 or b == 1)
9 | * 0 otherwise
10 | */
11 |
12 | CHIP Or {
13 | IN a, b;
14 | OUT out;
15 |
16 | PARTS:
17 | Not(in=a, out=nota);
18 | Not(in=b, out=notb);
19 | Nand(a=nota, b=notb, out=out);
20 | }
21 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/1. HalfAdder/HalfAdder.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/02/HalfAdder.hdl
5 |
6 | /**
7 | * Computes the sum of two bits.
8 | */
9 |
10 | CHIP HalfAdder {
11 | IN a, b; // 1-bit inputs
12 | OUT sum, // Right bit of a + b
13 | carry; // Left bit of a + b
14 |
15 | PARTS:
16 | Xor(a=a, b=b, out=sum);
17 | And(a=a, b=b, out=carry);
18 | }
19 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/6.DMUX/DMux.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/DMux.hdl
5 |
6 | /**
7 | * Demultiplexor:
8 | * {a, b} = {in, 0} if sel == 0
9 | * {0, in} if sel == 1
10 | */
11 |
12 | CHIP DMux {
13 | IN in, sel;
14 | OUT a, b;
15 |
16 | PARTS:
17 | Not(in=sel, out=notSel);
18 | And(a=in, b=notSel, out=a);
19 | And(a=in, b=sel, out=b);
20 | }
21 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/rect-test/Rect.hack:
--------------------------------------------------------------------------------
1 | 0000000000000000
2 | 1111110000010000
3 | 0000000000010111
4 | 1110001100000110
5 | 0000000000010000
6 | 1110001100001000
7 | 0100000000000000
8 | 1110110000010000
9 | 0000000000010001
10 | 1110001100001000
11 | 0000000000010001
12 | 1111110000100000
13 | 1110111010001000
14 | 0000000000010001
15 | 1111110000010000
16 | 0000000000100000
17 | 1110000010010000
18 | 0000000000010001
19 | 1110001100001000
20 | 0000000000010000
21 | 1111110010011000
22 | 0000000000001010
23 | 1110001100000001
24 | 0000000000010111
25 | 1110101010000111
26 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/Registers/Bit.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/03/a/Bit.hdl
5 |
6 | /**
7 | * 1-bit register:
8 | * If load[t] == 1 then out[t+1] = in[t]
9 | * else out does not change (out[t+1] = out[t])
10 | */
11 |
12 | CHIP Bit {
13 | IN in, load;
14 | OUT out;
15 |
16 | PARTS:
17 | Mux(a=dffout, b=in, sel=load, out=muxout);
18 | DFF(in=muxout, out=dffout, out=out);
19 | }
20 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/3. OR/Or.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Or.tst
5 |
6 | load Or.hdl,
7 | output-file Or.out,
8 | compare-to Or.cmp,
9 | output-list a%B3.1.3 b%B3.1.3 out%B3.1.3;
10 |
11 | set a 0,
12 | set b 0,
13 | eval,
14 | output;
15 |
16 | set a 0,
17 | set b 1,
18 | eval,
19 | output;
20 |
21 | set a 1,
22 | set b 0,
23 | eval,
24 | output;
25 |
26 | set a 1,
27 | set b 1,
28 | eval,
29 | output;
30 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/6.DMUX/DMux.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/DMux.tst
5 |
6 | load DMux.hdl,
7 | output-file DMux.out,
8 | compare-to DMux.cmp,
9 | output-list in%B3.1.3 sel%B3.1.3 a%B3.1.3 b%B3.1.3;
10 |
11 | set in 0,
12 | set sel 0,
13 | eval,
14 | output;
15 |
16 | set sel 1,
17 | eval,
18 | output;
19 |
20 | set in 1,
21 | set sel 0,
22 | eval,
23 | output;
24 |
25 | set sel 1,
26 | eval,
27 | output;
28 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/2. AND/And.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/And.tst
5 |
6 | load And.hdl,
7 | output-file And.out,
8 | compare-to And.cmp,
9 | output-list a%B3.1.3 b%B3.1.3 out%B3.1.3;
10 |
11 | set a 0,
12 | set b 0,
13 | eval,
14 | output;
15 |
16 | set a 0,
17 | set b 1,
18 | eval,
19 | output;
20 |
21 | set a 1,
22 | set b 0,
23 | eval,
24 | output;
25 |
26 | set a 1,
27 | set b 1,
28 | eval,
29 | output;
30 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/4. XOR/Xor.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Xor.tst
5 |
6 | load Xor.hdl,
7 | output-file Xor.out,
8 | compare-to Xor.cmp,
9 | output-list a%B3.1.3 b%B3.1.3 out%B3.1.3;
10 |
11 | set a 0,
12 | set b 0,
13 | eval,
14 | output;
15 |
16 | set a 0,
17 | set b 1,
18 | eval,
19 | output;
20 |
21 | set a 1,
22 | set b 0,
23 | eval,
24 | output;
25 |
26 | set a 1,
27 | set b 1,
28 | eval,
29 | output;
30 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/4. XOR/Xor.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Xor.hdl
5 |
6 | /**
7 | * Exclusive-or gate:
8 | * out = not (a == b)
9 | */
10 |
11 | CHIP Xor {
12 | IN a, b;
13 | OUT out;
14 |
15 | PARTS:
16 | Not(in=a, out=nota);
17 | Not(in=b, out=notb);
18 | And(a=nota, b=b, out=notaAndb);
19 | And(a=a, b=notb, out=aAndnotb);
20 | Or(a=notaAndb, b=aAndnotb, out=out);
21 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/5. MUX/Mux.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Mux.hdl
5 |
6 | /**
7 | * Multiplexor:
8 | * out = a if sel == 0
9 | * b otherwise
10 | */
11 |
12 | CHIP Mux {
13 | IN a, b, sel;
14 | OUT out;
15 |
16 | PARTS:
17 | Not(in=sel, out=notSel);
18 | And(a=a, b=notSel, out=aAndnotSel);
19 | And(a=b, b=sel, out=bAndsel);
20 | Or(a=aAndnotSel, b=bAndsel, out=out);
21 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/1. HalfAdder/HalfAdder.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/02/HalfAdder.tst
5 |
6 | load HalfAdder.hdl,
7 | output-file HalfAdder.out,
8 | compare-to HalfAdder.cmp,
9 | output-list a%B3.1.3 b%B3.1.3 sum%B3.1.3 carry%B3.1.3;
10 |
11 | set a 0,
12 | set b 0,
13 | eval,
14 | output;
15 |
16 | set a 0,
17 | set b 1,
18 | eval,
19 | output;
20 |
21 | set a 1,
22 | set b 0,
23 | eval,
24 | output;
25 |
26 | set a 1,
27 | set b 1,
28 | eval,
29 | output;
30 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/1. Or8Way/Or8Way.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Or8Way.tst
5 |
6 | load Or8Way.hdl,
7 | output-file Or8Way.out,
8 | compare-to Or8Way.cmp,
9 | output-list in%B2.8.2 out%B2.1.2;
10 |
11 | set in %B00000000,
12 | eval,
13 | output;
14 |
15 | set in %B11111111,
16 | eval,
17 | output;
18 |
19 | set in %B00010000,
20 | eval,
21 | output;
22 |
23 | set in %B00000001,
24 | eval,
25 | output;
26 |
27 | set in %B00100110,
28 | eval,
29 | output;
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/4. MUX16/Mux16.out:
--------------------------------------------------------------------------------
1 | | a | b | sel | out |
2 | | 0000000000000000 | 0000000000000000 | 0 | 0000000000000000 |
3 | | 0000000000000000 | 0000000000000000 | 1 | 0000000000000000 |
4 | | 0000000000000000 | 0001001000110100 | 0 | 0000000000000000 |
5 | | 0000000000000000 | 0001001000110100 | 1 | 0001001000110100 |
6 | | 1001100001110110 | 0000000000000000 | 0 | 1001100001110110 |
7 | | 1001100001110110 | 0000000000000000 | 1 | 0000000000000000 |
8 | | 1010101010101010 | 0101010101010101 | 0 | 1010101010101010 |
9 | | 1010101010101010 | 0101010101010101 | 1 | 0101010101010101 |
10 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/4. 16-bit Incrementer/Inc16.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/02/Inc16.tst
5 |
6 | load Inc16.hdl,
7 | output-file Inc16.out,
8 | compare-to Inc16.cmp,
9 | output-list in%B1.16.1 out%B1.16.1;
10 |
11 | set in %B0000000000000000, // in = 0
12 | eval,
13 | output;
14 |
15 | set in %B1111111111111111, // in = -1
16 | eval,
17 | output;
18 |
19 | set in %B0000000000000101, // in = 5
20 | eval,
21 | output;
22 |
23 | set in %B1111111111111011, // in = -5
24 | eval,
25 | output;
26 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/4. MUX16/Mux16.cmp:
--------------------------------------------------------------------------------
1 | | a | b | sel | out |
2 | | 0000000000000000 | 0000000000000000 | 0 | 0000000000000000 |
3 | | 0000000000000000 | 0000000000000000 | 1 | 0000000000000000 |
4 | | 0000000000000000 | 0001001000110100 | 0 | 0000000000000000 |
5 | | 0000000000000000 | 0001001000110100 | 1 | 0001001000110100 |
6 | | 1001100001110110 | 0000000000000000 | 0 | 1001100001110110 |
7 | | 1001100001110110 | 0000000000000000 | 1 | 0000000000000000 |
8 | | 1010101010101010 | 0101010101010101 | 0 | 1010101010101010 |
9 | | 1010101010101010 | 0101010101010101 | 1 | 0101010101010101 |
10 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/1. NOT16/Not16.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Not16.tst
5 |
6 | load Not16.hdl,
7 | output-file Not16.out,
8 | compare-to Not16.cmp,
9 | output-list in%B1.16.1 out%B1.16.1;
10 |
11 | set in %B0000000000000000,
12 | eval,
13 | output;
14 |
15 | set in %B1111111111111111,
16 | eval,
17 | output;
18 |
19 | set in %B1010101010101010,
20 | eval,
21 | output;
22 |
23 | set in %B0011110011000011,
24 | eval,
25 | output;
26 |
27 | set in %B0001001000110100,
28 | eval,
29 | output;
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/2. MUX4Way16/Mux4Way16.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Mux4Way16.hdl
5 |
6 | /**
7 | * 4-way 16-bit multiplexor:
8 | * out = a if sel == 00
9 | * b if sel == 01
10 | * c if sel == 10
11 | * d if sel == 11
12 | */
13 |
14 | CHIP Mux4Way16 {
15 | IN a[16], b[16], c[16], d[16], sel[2];
16 | OUT out[16];
17 |
18 | PARTS:
19 | Mux16(a=a, b=b, sel=sel[0], out=muxab);
20 | Mux16(a=c, b=d, sel=sel[0], out=muxcd);
21 | Mux16(a=muxab, b=muxcd, sel=sel[1], out=out);
22 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/2. FullAdder/FullAdder.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/02/FullAdder.hdl
5 |
6 | /**
7 | * Computes the sum of three bits.
8 | */
9 |
10 | CHIP FullAdder {
11 | IN a, b, c; // 1-bit inputs
12 | OUT sum, // Right bit of a + b + c
13 | carry; // Left bit of a + b + c
14 |
15 | PARTS:
16 | Xor(a=b, b=c, out=xorbc);
17 | Not(in=xorbc, out=xnorbc);
18 | And(a=b, b=c, out=andbc);
19 | Or(a=b, b=c, out=orbc);
20 | Mux(a=xorbc, b=xnorbc, sel=a, out=sum);
21 | Mux(a=andbc, b=orbc, sel=a, out=carry);
22 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/1. Or8Way/Or8Way.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Or8Way.hdl
5 |
6 | /**
7 | * 8-way Or:
8 | * out = (in[0] or in[1] or ... or in[7])
9 | */
10 |
11 | CHIP Or8Way {
12 | IN in[8];
13 | OUT out;
14 |
15 | PARTS:
16 | Or(a=in[0], b=in[1], out=or01);
17 | Or(a=in[2], b=or01, out=or012);
18 | Or(a=in[3], b=or012, out=or0123);
19 | Or(a=in[4], b=or0123, out=or01234);
20 | Or(a=in[5], b=or01234, out=or012345);
21 | Or(a=in[6], b=or012345, out=or0123456);
22 | Or(a=in[7], b=or0123456, out=out);
23 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/add-test/ComputerAdd-external.out:
--------------------------------------------------------------------------------
1 | | time |reset|RAM16K[0]|RAM16K[1]|RAM16K[2]|
2 | | 0 | 0 | 0 | 0 | 0 |
3 | | 1 | 0 | 0 | 0 | 0 |
4 | | 2 | 0 | 0 | 0 | 0 |
5 | | 3 | 0 | 0 | 0 | 0 |
6 | | 4 | 0 | 0 | 0 | 0 |
7 | | 5 | 0 | 0 | 0 | 0 |
8 | | 6 | 0 | 5 | 0 | 0 |
9 | | 7 | 1 | 0 | 0 | 0 |
10 | | 8 | 0 | 0 | 0 | 0 |
11 | | 9 | 0 | 0 | 0 | 0 |
12 | | 10 | 0 | 0 | 0 | 0 |
13 | | 11 | 0 | 0 | 0 | 0 |
14 | | 12 | 0 | 0 | 0 | 0 |
15 | | 13 | 0 | 5 | 0 | 0 |
16 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/add-test/ComputerAdd-external.cmp:
--------------------------------------------------------------------------------
1 | | time |reset|RAM16K[0]|RAM16K[1]|RAM16K[2]|
2 | | 0 | 0 | 0 | 0 | 0 |
3 | | 1 | 0 | 0 | 0 | 0 |
4 | | 2 | 0 | 0 | 0 | 0 |
5 | | 3 | 0 | 0 | 0 | 0 |
6 | | 4 | 0 | 0 | 0 | 0 |
7 | | 5 | 0 | 0 | 0 | 0 |
8 | | 6 | 0 | 5 | 0 | 0 |
9 | | 7 | 1 | 0 | 0 | 0 |
10 | | 8 | 0 | 0 | 0 | 0 |
11 | | 9 | 0 | 0 | 0 | 0 |
12 | | 10 | 0 | 0 | 0 | 0 |
13 | | 11 | 0 | 0 | 0 | 0 |
14 | | 12 | 0 | 0 | 0 | 0 |
15 | | 13 | 0 | 5 | 0 | 0 |
16 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/4. Hack Assembly Programming/mult/Mult.hack:
--------------------------------------------------------------------------------
1 | 0000000000000000
2 | 1111110000010000
3 | 0000000000010000
4 | 1110001100001000
5 | 0000000000000001
6 | 1111110000010000
7 | 0000000000010001
8 | 1110001100001000
9 | 0000000000010010
10 | 1110101010001000
11 | 0000000000010011
12 | 1110101010001000
13 | 0000000000000010
14 | 1110101010001000
15 | 0000000000010011
16 | 1111110000010000
17 | 0000000000010000
18 | 1111010011010000
19 | 0000000000011110
20 | 1110001100000010
21 | 0000000000010010
22 | 1111110000010000
23 | 0000000000010001
24 | 1111000010010000
25 | 0000000000010010
26 | 1110001100001000
27 | 0000000000010011
28 | 1111110111001000
29 | 0000000000001110
30 | 1110101010000111
31 | 0000000000010010
32 | 1111110000010000
33 | 0000000000000010
34 | 1110001100001000
35 | 0000000000100010
36 | 1110101010000111
37 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/3. Mux8Way16/Mux8Way16.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Mux8Way16.hdl
5 |
6 | /**
7 | * 8-way 16-bit multiplexor:
8 | * out = a if sel == 000
9 | * b if sel == 001
10 | * etc.
11 | * h if sel == 111
12 | */
13 |
14 | CHIP Mux8Way16 {
15 | IN a[16], b[16], c[16], d[16],
16 | e[16], f[16], g[16], h[16],
17 | sel[3];
18 | OUT out[16];
19 |
20 | PARTS:
21 | Mux4Way16(a=a, b=b, c=c, d=d, sel=sel[0..1], out=muxabcd);
22 | Mux4Way16(a=e, b=f, c=g, d=h, sel=sel[0..1], out=muxefgh);
23 | Mux16(a=muxabcd, b=muxefgh, sel=sel[2], out=out);
24 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/4.DMux4Way/DMux4Way.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/DMux4Way.tst
5 |
6 | load DMux4Way.hdl,
7 | output-file DMux4Way.out,
8 | compare-to DMux4Way.cmp,
9 | output-list in%B2.1.2 sel%B2.2.2 a%B2.1.2 b%B2.1.2 c%B2.1.2 d%B2.1.2;
10 |
11 | set in 0,
12 | set sel %B00,
13 | eval,
14 | output;
15 |
16 | set sel %B01,
17 | eval,
18 | output;
19 |
20 | set sel %B10,
21 | eval,
22 | output;
23 |
24 | set sel %B11,
25 | eval,
26 | output;
27 |
28 | set in 1,
29 | set sel %B00,
30 | eval,
31 | output;
32 |
33 | set sel %B01,
34 | eval,
35 | output;
36 |
37 | set sel %B10,
38 | eval,
39 | output;
40 |
41 | set sel %B11,
42 | eval,
43 | output;
44 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/2. FullAdder/FullAdder.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/02/FullAdder.tst
5 |
6 | load FullAdder.hdl,
7 | output-file FullAdder.out,
8 | compare-to FullAdder.cmp,
9 | output-list a%B3.1.3 b%B3.1.3 c%B3.1.3 sum%B3.1.3 carry%B3.1.3;
10 |
11 | set a 0,
12 | set b 0,
13 | set c 0,
14 | eval,
15 | output;
16 |
17 | set c 1,
18 | eval,
19 | output;
20 |
21 | set b 1,
22 | set c 0,
23 | eval,
24 | output;
25 |
26 | set c 1,
27 | eval,
28 | output;
29 |
30 | set a 1,
31 | set b 0,
32 | set c 0,
33 | eval,
34 | output;
35 |
36 | set c 1,
37 | eval,
38 | output;
39 |
40 | set b 1,
41 | set c 0,
42 | eval,
43 | output;
44 |
45 | set c 1,
46 | eval,
47 | output;
48 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/elementary gates/5. MUX/Mux.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Mux.tst
5 |
6 | load Mux.hdl,
7 | output-file Mux.out,
8 | compare-to Mux.cmp,
9 | output-list a%B3.1.3 b%B3.1.3 sel%B3.1.3 out%B3.1.3;
10 |
11 | set a 0,
12 | set b 0,
13 | set sel 0,
14 | eval,
15 | output;
16 |
17 | set sel 1,
18 | eval,
19 | output;
20 |
21 | set a 0,
22 | set b 1,
23 | set sel 0,
24 | eval,
25 | output;
26 |
27 | set sel 1,
28 | eval,
29 | output;
30 |
31 | set a 1,
32 | set b 0,
33 | set sel 0,
34 | eval,
35 | output;
36 |
37 | set sel 1,
38 | eval,
39 | output;
40 |
41 | set a 1,
42 | set b 1,
43 | set sel 0,
44 | eval,
45 | output;
46 |
47 | set sel 1,
48 | eval,
49 | output;
50 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/rect-test/ComputerRect-external.out:
--------------------------------------------------------------------------------
1 | | time |
2 | | 0 |
3 | | 1 |
4 | | 2 |
5 | | 3 |
6 | | 4 |
7 | | 5 |
8 | | 6 |
9 | | 7 |
10 | | 8 |
11 | | 9 |
12 | | 10 |
13 | | 11 |
14 | | 12 |
15 | | 13 |
16 | | 14 |
17 | | 15 |
18 | | 16 |
19 | | 17 |
20 | | 18 |
21 | | 19 |
22 | | 20 |
23 | | 21 |
24 | | 22 |
25 | | 23 |
26 | | 24 |
27 | | 25 |
28 | | 26 |
29 | | 27 |
30 | | 28 |
31 | | 29 |
32 | | 30 |
33 | | 31 |
34 | | 32 |
35 | | 33 |
36 | | 34 |
37 | | 35 |
38 | | 36 |
39 | | 37 |
40 | | 38 |
41 | | 39 |
42 | | 40 |
43 | | 41 |
44 | | 42 |
45 | | 43 |
46 | | 44 |
47 | | 45 |
48 | | 46 |
49 | | 47 |
50 | | 48 |
51 | | 49 |
52 | | 50 |
53 | | 51 |
54 | | 52 |
55 | | 53 |
56 | | 54 |
57 | | 55 |
58 | | 56 |
59 | | 57 |
60 | | 58 |
61 | | 59 |
62 | | 60 |
63 | | 61 |
64 | | 62 |
65 | | 63 |
66 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/3. OR16/Or16.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Or16.tst
5 |
6 | load Or16.hdl,
7 | output-file Or16.out,
8 | compare-to Or16.cmp,
9 | output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
10 |
11 | set a %B0000000000000000,
12 | set b %B0000000000000000,
13 | eval,
14 | output;
15 |
16 | set a %B0000000000000000,
17 | set b %B1111111111111111,
18 | eval,
19 | output;
20 |
21 | set a %B1111111111111111,
22 | set b %B1111111111111111,
23 | eval,
24 | output;
25 |
26 | set a %B1010101010101010,
27 | set b %B0101010101010101,
28 | eval,
29 | output;
30 |
31 | set a %B0011110011000011,
32 | set b %B0000111111110000,
33 | eval,
34 | output;
35 |
36 | set a %B0001001000110100,
37 | set b %B1001100001110110,
38 | eval,
39 | output;
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/2. AND16/And16.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/And16.tst
5 |
6 | load And16.hdl,
7 | output-file And16.out,
8 | compare-to And16.cmp,
9 | output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
10 |
11 | set a %B0000000000000000,
12 | set b %B0000000000000000,
13 | eval,
14 | output;
15 |
16 | set a %B0000000000000000,
17 | set b %B1111111111111111,
18 | eval,
19 | output;
20 |
21 | set a %B1111111111111111,
22 | set b %B1111111111111111,
23 | eval,
24 | output;
25 |
26 | set a %B1010101010101010,
27 | set b %B0101010101010101,
28 | eval,
29 | output;
30 |
31 | set a %B0011110011000011,
32 | set b %B0000111111110000,
33 | eval,
34 | output;
35 |
36 | set a %B0001001000110100,
37 | set b %B1001100001110110,
38 | eval,
39 | output;
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/Adders/3. 16-bit Adder/Add16.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/02/Add16.tst
5 |
6 | load Add16.hdl,
7 | output-file Add16.out,
8 | compare-to Add16.cmp,
9 | output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
10 |
11 | set a %B0000000000000000,
12 | set b %B0000000000000000,
13 | eval,
14 | output;
15 |
16 | set a %B0000000000000000,
17 | set b %B1111111111111111,
18 | eval,
19 | output;
20 |
21 | set a %B1111111111111111,
22 | set b %B1111111111111111,
23 | eval,
24 | output;
25 |
26 | set a %B1010101010101010,
27 | set b %B0101010101010101,
28 | eval,
29 | output;
30 |
31 | set a %B0011110011000011,
32 | set b %B0000111111110000,
33 | eval,
34 | output;
35 |
36 | set a %B0001001000110100,
37 | set b %B1001100001110110,
38 | eval,
39 | output;
40 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/4.DMux4Way/DMux4Way.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/DMux4Way.hdl
5 |
6 | /**
7 | * 4-way demultiplexor:
8 | * {a, b, c, d} = {in, 0, 0, 0} if sel == 00
9 | * {0, in, 0, 0} if sel == 01
10 | * {0, 0, in, 0} if sel == 10
11 | * {0, 0, 0, in} if sel == 11
12 | */
13 |
14 | CHIP DMux4Way {
15 | IN in, sel[2];
16 | OUT a, b, c, d;
17 |
18 | PARTS:
19 | DMux(in=in, sel=sel[0], a=dmux00, b=dmux01);
20 | DMux(in=in, sel=sel[0], a=dmux10, b=dmux11);
21 | Not(in=sel[1], out=notsel1);
22 | And(a=notsel1, b=dmux00, out=a);
23 | And(a=notsel1, b=dmux01, out=b);
24 | And(a=sel[1], b=dmux10, out=c);
25 | And(a=sel[1], b=dmux11, out=d);
26 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/Program Counter/PC.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/03/a/PC.hdl
5 |
6 | /**
7 | * A 16-bit counter with load and reset control bits.
8 | * if (reset[t] == 1) out[t+1] = 0
9 | * else if (load[t] == 1) out[t+1] = in[t]
10 | * else if (inc[t] == 1) out[t+1] = out[t] + 1 (integer addition)
11 | * else out[t+1] = out[t]
12 | */
13 |
14 | CHIP PC {
15 | IN in[16],load,inc,reset;
16 | OUT out[16];
17 |
18 | PARTS:
19 | Inc16(in=regout, out=regoutplus1);
20 | Mux16(a=regout, b=regoutplus1, sel=inc, out=incResult);
21 | Mux16(a=incResult, b=in, sel=load, out=loadResult);
22 | Mux16(a=loadResult, b=false, sel=reset, out=resetResult);
23 | Register(in=resetResult, load=true, out=regout, out=out);
24 | }
25 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/4. MUX16/Mux16.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Mux16.tst
5 |
6 | load Mux16.hdl,
7 | output-file Mux16.out,
8 | compare-to Mux16.cmp,
9 | output-list a%B1.16.1 b%B1.16.1 sel%D2.1.2 out%B1.16.1;
10 |
11 | set a 0,
12 | set b 0,
13 | set sel 0,
14 | eval,
15 | output;
16 |
17 | set sel 1,
18 | eval,
19 | output;
20 |
21 | set a %B0000000000000000,
22 | set b %B0001001000110100,
23 | set sel 0,
24 | eval,
25 | output;
26 |
27 | set sel 1,
28 | eval,
29 | output;
30 |
31 | set a %B1001100001110110,
32 | set b %B0000000000000000,
33 | set sel 0,
34 | eval,
35 | output;
36 |
37 | set sel 1,
38 | eval,
39 | output;
40 |
41 | set a %B1010101010101010,
42 | set b %B0101010101010101,
43 | set sel 0,
44 | eval,
45 | output;
46 |
47 | set sel 1,
48 | eval,
49 | output;
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/add-test/ComputerAdd-external.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/05/ComputerAdd-external.tst
5 |
6 | load Computer.hdl,
7 | output-file ComputerAdd-external.out,
8 | compare-to ComputerAdd-external.cmp,
9 | output-list time%S1.4.1 reset%B2.1.2 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1;
10 |
11 | // Load a program written in the Hack machine language.
12 | // The program adds the two constants 2 and 3 and writes the result in RAM[0].
13 | ROM32K load Add.hack,
14 | output;
15 |
16 | // First run (at the beginning PC=0)
17 | repeat 6 {
18 | tick, tock, output;
19 | }
20 |
21 | // Reset the PC
22 | set reset 1,
23 | set RAM16K[0] 0,
24 | tick, tock, output;
25 |
26 |
27 | // Second run, to check that the PC was reset correctly.
28 | set reset 0,
29 |
30 | repeat 6 {
31 | tick, tock, output;
32 | }
33 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/rect-test/ComputerRect-external.cmp:
--------------------------------------------------------------------------------
1 | | time |
2 | | 0 |
3 | | 1 |
4 | | 2 |
5 | | 3 |
6 | | 4 |
7 | | 5 |
8 | | 6 |
9 | | 7 |
10 | | 8 |
11 | | 9 |
12 | | 10 |
13 | | 11 |
14 | | 12 |
15 | | 13 |
16 | | 14 |
17 | | 15 |
18 | | 16 |
19 | | 17 |
20 | | 18 |
21 | | 19 |
22 | | 20 |
23 | | 21 |
24 | | 22 |
25 | | 23 |
26 | | 24 |
27 | | 25 |
28 | | 26 |
29 | | 27 |
30 | | 28 |
31 | | 29 |
32 | | 30 |
33 | | 31 |
34 | | 32 |
35 | | 33 |
36 | | 34 |
37 | | 35 |
38 | | 36 |
39 | | 37 |
40 | | 38 |
41 | | 39 |
42 | | 40 |
43 | | 41 |
44 | | 42 |
45 | | 43 |
46 | | 44 |
47 | | 45 |
48 | | 46 |
49 | | 47 |
50 | | 48 |
51 | | 49 |
52 | | 50 |
53 | | 51 |
54 | | 52 |
55 | | 53 |
56 | | 54 |
57 | | 55 |
58 | | 56 |
59 | | 57 |
60 | | 58 |
61 | | 59 |
62 | | 60 |
63 | | 61 |
64 | | 62 |
65 | | 63 |
66 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/rect-test/ComputerRect-external.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/05/ComputerRect-external.tst
5 |
6 | load Computer.hdl,
7 | output-file ComputerRect-external.out,
8 | compare-to ComputerRect-external.cmp,
9 | output-list time%S1.4.1;
10 |
11 | // Load a program written in the Hack machine language.
12 | // The program draws a rectangle of width 16 pixels and
13 | // length RAM[0] at the top left of the screen.
14 | ROM32K load Rect.hack,
15 |
16 | echo "Before you run this script, select the 'Screen' option from the 'View' menu";
17 |
18 | echo "A small rectangle should be drawn at the top left of the screen (the 'Screen' option of the 'View' menu should be selected.)";
19 |
20 | // draw a rectangle 16 pixels wide and 4 pixels long
21 | set RAM16K[0] 4,
22 | output;
23 |
24 | repeat 63 {
25 | tick, tock, output;
26 | }
27 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/2. MUX4Way16/Mux4Way16.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Mux4Way16.tst
5 |
6 | load Mux4Way16.hdl,
7 | output-file Mux4Way16.out,
8 | compare-to Mux4Way16.cmp,
9 | output-list a%B1.16.1 b%B1.16.1 c%B1.16.1 d%B1.16.1 sel%B2.2.2 out%B1.16.1;
10 |
11 | set a 0,
12 | set b 0,
13 | set c 0,
14 | set d 0,
15 | set sel 0,
16 | eval,
17 | output;
18 |
19 | set sel 1,
20 | eval,
21 | output;
22 |
23 | set sel 2,
24 | eval,
25 | output;
26 |
27 | set sel 3,
28 | eval,
29 | output;
30 |
31 | set a %B0001001000110100,
32 | set b %B1001100001110110,
33 | set c %B1010101010101010,
34 | set d %B0101010101010101,
35 | set sel 0,
36 | eval,
37 | output;
38 |
39 | set sel 1,
40 | eval,
41 | output;
42 |
43 | set sel 2,
44 | eval,
45 | output;
46 |
47 | set sel 3,
48 | eval,
49 | output;
50 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/add-test/ComputerAdd.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/05/ComputerAdd.tst
5 |
6 | load Computer.hdl,
7 | output-file ComputerAdd.out,
8 | compare-to ComputerAdd.cmp,
9 | output-list time%S1.4.1 reset%B2.1.2 ARegister[0]%D1.7.1 DRegister[0]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1;
10 |
11 | // Load a program written in the Hack machine language.
12 | // The program adds the two constants 2 and 3 and writes the result in RAM[0].
13 | ROM32K load Add.hack,
14 | output;
15 |
16 | // First run (at the beginning PC=0)
17 | repeat 6 {
18 | tick, tock, output;
19 | }
20 |
21 | // Reset the PC
22 | set reset 1,
23 | set RAM16K[0] 0,
24 | tick, tock, output;
25 |
26 |
27 | // Second run, to check that the PC was reset correctly.
28 | set reset 0,
29 |
30 | repeat 6 {
31 | tick, tock, output;
32 | }
33 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/2. MUX4Way16/Mux4Way16.out:
--------------------------------------------------------------------------------
1 | | a | b | c | d | sel | out |
2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 00 | 0000000000000000 |
3 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 01 | 0000000000000000 |
4 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 10 | 0000000000000000 |
5 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 11 | 0000000000000000 |
6 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 00 | 0001001000110100 |
7 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 01 | 1001100001110110 |
8 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 10 | 1010101010101010 |
9 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 11 | 0101010101010101 |
10 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/2. MUX4Way16/Mux4Way16.cmp:
--------------------------------------------------------------------------------
1 | | a | b | c | d | sel | out |
2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 00 | 0000000000000000 |
3 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 01 | 0000000000000000 |
4 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 10 | 0000000000000000 |
5 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 11 | 0000000000000000 |
6 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 00 | 0001001000110100 |
7 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 01 | 1001100001110110 |
8 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 10 | 1010101010101010 |
9 | | 0001001000110100 | 1001100001110110 | 1010101010101010 | 0101010101010101 | 11 | 0101010101010101 |
10 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/rect-test/ComputerRect.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/05/ComputerRect.tst
5 |
6 | load Computer.hdl,
7 | output-file ComputerRect.out,
8 | compare-to ComputerRect.cmp,
9 | output-list time%S1.4.1 ARegister[]%D1.7.1 DRegister[]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1;
10 |
11 | // Load a program written in the Hack machine language.
12 | // The program draws a rectangle of width 16 pixels and
13 | // length RAM[0] at the top left of the screen.
14 | ROM32K load Rect.hack,
15 |
16 | echo "Before you run this script, select the 'Screen' option from the 'View' menu";
17 |
18 | echo "A small rectangle should be drawn at the top left of the screen (the 'Screen' option of the 'View' menu should be selected.)";
19 |
20 | // Draws a rectangle 16 pixels wide and 4 pixels long
21 | set RAM16K[0] 4,
22 | output;
23 |
24 | repeat 63 {
25 | tick, tock, output;
26 | }
27 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/1. NOT16/Not16.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Not16.hdl
5 |
6 | /**
7 | * 16-bit Not:
8 | * for i=0..15: out[i] = not in[i]
9 | */
10 |
11 | CHIP Not16 {
12 | IN in[16];
13 | OUT out[16];
14 |
15 | PARTS:
16 | Not(in=in[0], out=out[0]);
17 | Not(in=in[1], out=out[1]);
18 | Not(in=in[2], out=out[2]);
19 | Not(in=in[3], out=out[3]);
20 | Not(in=in[4], out=out[4]);
21 | Not(in=in[5], out=out[5]);
22 | Not(in=in[6], out=out[6]);
23 | Not(in=in[7], out=out[7]);
24 | Not(in=in[8], out=out[8]);
25 | Not(in=in[9], out=out[9]);
26 | Not(in=in[10], out=out[10]);
27 | Not(in=in[11], out=out[11]);
28 | Not(in=in[12], out=out[12]);
29 | Not(in=in[13], out=out[13]);
30 | Not(in=in[14], out=out[14]);
31 | Not(in=in[15], out=out[15]);
32 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/Computer.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/05/Computer.hdl
5 |
6 | /**
7 | * The HACK computer, including CPU, ROM and RAM.
8 | * When reset is 0, the program stored in the computer's ROM executes.
9 | * When reset is 1, the execution of the program restarts.
10 | * Thus, to start a program's execution, reset must be pushed "up" (1)
11 | * and "down" (0). From this point onward the user is at the mercy of
12 | * the software. In particular, depending on the program's code, the
13 | * screen may show some output and the user may be able to interact
14 | * with the computer via the keyboard.
15 | */
16 |
17 | CHIP Computer {
18 |
19 | IN reset;
20 |
21 | PARTS:
22 | ROM32K(address=cpuPc, out=romOut);
23 | CPU(inM=memoryOut, instruction=romOut, reset=reset, outM=cpuOutM, writeM=cpuWriteM, addressM=cpuAddressM, pc=cpuPc);
24 | Memory(in=cpuOutM, load=cpuWriteM, address=cpuAddressM, out=memoryOut);
25 | }
26 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/add-test/ComputerAdd.out:
--------------------------------------------------------------------------------
1 | | time |reset|ARegister|DRegister|PC[]|RAM16K[0]|RAM16K[1]|RAM16K[2]|
2 | | 0 | 0 | 0 | 0 | 0| 0 | 0 | 0 |
3 | | 1 | 0 | 2 | 0 | 1| 0 | 0 | 0 |
4 | | 2 | 0 | 2 | 2 | 2| 0 | 0 | 0 |
5 | | 3 | 0 | 3 | 2 | 3| 0 | 0 | 0 |
6 | | 4 | 0 | 3 | 5 | 4| 0 | 0 | 0 |
7 | | 5 | 0 | 0 | 5 | 5| 0 | 0 | 0 |
8 | | 6 | 0 | 0 | 5 | 6| 5 | 0 | 0 |
9 | | 7 | 1 | 0 | 5 | 0| 0 | 0 | 0 |
10 | | 8 | 0 | 2 | 5 | 1| 0 | 0 | 0 |
11 | | 9 | 0 | 2 | 2 | 2| 0 | 0 | 0 |
12 | | 10 | 0 | 3 | 2 | 3| 0 | 0 | 0 |
13 | | 11 | 0 | 3 | 5 | 4| 0 | 0 | 0 |
14 | | 12 | 0 | 0 | 5 | 5| 0 | 0 | 0 |
15 | | 13 | 0 | 0 | 5 | 6| 5 | 0 | 0 |
16 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/add-test/ComputerAdd.cmp:
--------------------------------------------------------------------------------
1 | | time |reset|ARegister|DRegister|PC[]|RAM16K[0]|RAM16K[1]|RAM16K[2]|
2 | | 0 | 0 | 0 | 0 | 0| 0 | 0 | 0 |
3 | | 1 | 0 | 2 | 0 | 1| 0 | 0 | 0 |
4 | | 2 | 0 | 2 | 2 | 2| 0 | 0 | 0 |
5 | | 3 | 0 | 3 | 2 | 3| 0 | 0 | 0 |
6 | | 4 | 0 | 3 | 5 | 4| 0 | 0 | 0 |
7 | | 5 | 0 | 0 | 5 | 5| 0 | 0 | 0 |
8 | | 6 | 0 | 0 | 5 | 6| 5 | 0 | 0 |
9 | | 7 | 1 | 0 | 5 | 0| 0 | 0 | 0 |
10 | | 8 | 0 | 2 | 5 | 1| 0 | 0 | 0 |
11 | | 9 | 0 | 2 | 2 | 2| 0 | 0 | 0 |
12 | | 10 | 0 | 3 | 2 | 3| 0 | 0 | 0 |
13 | | 11 | 0 | 3 | 5 | 4| 0 | 0 | 0 |
14 | | 12 | 0 | 0 | 5 | 5| 0 | 0 | 0 |
15 | | 13 | 0 | 0 | 5 | 6| 5 | 0 | 0 |
16 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/max-test/ComputerMax-external.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/05/ComputerMax-external.tst
5 |
6 | load Computer.hdl,
7 | output-file ComputerMax-external.out,
8 | compare-to ComputerMax-external.cmp,
9 | output-list time%S1.4.1 reset%B2.1.2 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1;
10 |
11 | // Load a program written in the Hack machine language.
12 | // The program computes the maximum of RAM[0] and RAM[1]
13 | // and writes the result in RAM[2].
14 | ROM32K load Max.hack,
15 |
16 | // first run: compute max(3,5)
17 | set RAM16K[0] 3,
18 | set RAM16K[1] 5,
19 | output;
20 |
21 | repeat 14 {
22 | tick, tock, output;
23 | }
24 |
25 | // reset the PC
26 | set reset 1,
27 | tick, tock, output;
28 |
29 | // second run: compute max(23456,12345)
30 | set reset 0,
31 | set RAM16K[0] 23456,
32 | set RAM16K[1] 12345,
33 | output;
34 |
35 | // The run on these inputs needs less cycles (different branching)
36 | repeat 10 {
37 | tick, tock, output;
38 | }
39 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/max-test/ComputerMax.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/05/ComputerMax.tst
5 |
6 | load Computer.hdl,
7 | output-file ComputerMax.out,
8 | compare-to ComputerMax.cmp,
9 | output-list time%S1.4.1 reset%B2.1.2 ARegister[]%D1.7.1 DRegister[]%D1.7.1 PC[]%D0.4.0 RAM16K[0]%D1.7.1 RAM16K[1]%D1.7.1 RAM16K[2]%D1.7.1;
10 |
11 | // Load a program written in the Hack machine language.
12 | // The program computes the maximum of RAM[0] and RAM[1]
13 | // and writes the result in RAM[2].
14 |
15 | ROM32K load Max.hack,
16 |
17 | // first run: compute max(3,5)
18 | set RAM16K[0] 3,
19 | set RAM16K[1] 5,
20 | output;
21 |
22 | repeat 14 {
23 | tick, tock, output;
24 | }
25 |
26 | // reset the PC
27 | set reset 1,
28 | tick, tock, output;
29 |
30 | // second run: compute max(23456,12345)
31 | set reset 0,
32 | set RAM16K[0] 23456,
33 | set RAM16K[1] 12345,
34 | output;
35 |
36 | // The run on these inputs needs less cycles (different branching)
37 | repeat 10 {
38 | tick, tock, output;
39 | }
40 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/3. OR16/Or16.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Or16.hdl
5 |
6 | /**
7 | * 16-bit bitwise Or:
8 | * for i = 0..15 out[i] = (a[i] or b[i])
9 | */
10 |
11 | CHIP Or16 {
12 | IN a[16], b[16];
13 | OUT out[16];
14 |
15 | PARTS:
16 | Or(a=a[0], b=b[0], out=out[0]);
17 | Or(a=a[1], b=b[1], out=out[1]);
18 | Or(a=a[2], b=b[2], out=out[2]);
19 | Or(a=a[3], b=b[3], out=out[3]);
20 | Or(a=a[4], b=b[4], out=out[4]);
21 | Or(a=a[5], b=b[5], out=out[5]);
22 | Or(a=a[6], b=b[6], out=out[6]);
23 | Or(a=a[7], b=b[7], out=out[7]);
24 | Or(a=a[8], b=b[8], out=out[8]);
25 | Or(a=a[9], b=b[9], out=out[9]);
26 | Or(a=a[10], b=b[10], out=out[10]);
27 | Or(a=a[11], b=b[11], out=out[11]);
28 | Or(a=a[12], b=b[12], out=out[12]);
29 | Or(a=a[13], b=b[13], out=out[13]);
30 | Or(a=a[14], b=b[14], out=out[14]);
31 | Or(a=a[15], b=b[15], out=out[15]);
32 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/2. AND16/And16.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/And16.hdl
5 |
6 | /**
7 | * 16-bit bitwise And:
8 | * for i = 0..15: out[i] = (a[i] and b[i])
9 | */
10 |
11 | CHIP And16 {
12 | IN a[16], b[16];
13 | OUT out[16];
14 |
15 | PARTS:
16 | And(a=a[0], b=b[0], out=out[0]);
17 | And(a=a[1], b=b[1], out=out[1]);
18 | And(a=a[2], b=b[2], out=out[2]);
19 | And(a=a[3], b=b[3], out=out[3]);
20 | And(a=a[4], b=b[4], out=out[4]);
21 | And(a=a[5], b=b[5], out=out[5]);
22 | And(a=a[6], b=b[6], out=out[6]);
23 | And(a=a[7], b=b[7], out=out[7]);
24 | And(a=a[8], b=b[8], out=out[8]);
25 | And(a=a[9], b=b[9], out=out[9]);
26 | And(a=a[10], b=b[10], out=out[10]);
27 | And(a=a[11], b=b[11], out=out[11]);
28 | And(a=a[12], b=b[12], out=out[12]);
29 | And(a=a[13], b=b[13], out=out[13]);
30 | And(a=a[14], b=b[14], out=out[14]);
31 | And(a=a[15], b=b[15], out=out[15]);
32 | }
33 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/5.DMux8Way/DMux8Way.out:
--------------------------------------------------------------------------------
1 | | in | sel | a | b | c | d | e | f | g | h |
2 | | 0 | 000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
3 | | 0 | 001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
4 | | 0 | 010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
5 | | 0 | 011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
6 | | 0 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
7 | | 0 | 101 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
8 | | 0 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
9 | | 0 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
10 | | 1 | 000 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
11 | | 1 | 001 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
12 | | 1 | 010 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
13 | | 1 | 011 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
14 | | 1 | 100 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
15 | | 1 | 101 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
16 | | 1 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
17 | | 1 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
18 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/RAMn/RAM16K.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/03/b/RAM16K.hdl
5 |
6 | /**
7 | * Memory of 16K registers, each 16 bit-wide. Out holds the value
8 | * stored at the memory location specified by address. If load==1, then
9 | * the in value is loaded into the memory location specified by address
10 | * (the loaded value will be emitted to out from the next time step onward).
11 | */
12 |
13 | CHIP RAM16K {
14 | IN in[16], load, address[14];
15 | OUT out[16];
16 |
17 | PARTS:
18 | DMux4Way(in=load, sel=address[12..13], a=ram4k0load, b=ram4k1load, c=ram4k2load, d=ram4k3load);
19 | RAM4K(in=in, load=ram4k0load, address=address[0..11], out=ram4k0out);
20 | RAM4K(in=in, load=ram4k1load, address=address[0..11], out=ram4k1out);
21 | RAM4K(in=in, load=ram4k2load, address=address[0..11], out=ram4k2out);
22 | RAM4K(in=in, load=ram4k3load, address=address[0..11], out=ram4k3out);
23 | Mux4Way16(a=ram4k0out, b=ram4k1out, c=ram4k2out, d=ram4k3out, sel=address[12..13], out=out);
24 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/5.DMux8Way/DMux8Way.cmp:
--------------------------------------------------------------------------------
1 | | in | sel | a | b | c | d | e | f | g | h |
2 | | 0 | 000 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
3 | | 0 | 001 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
4 | | 0 | 010 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
5 | | 0 | 011 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
6 | | 0 | 100 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
7 | | 0 | 101 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
8 | | 0 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
9 | | 0 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
10 | | 1 | 000 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
11 | | 1 | 001 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
12 | | 1 | 010 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
13 | | 1 | 011 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
14 | | 1 | 100 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
15 | | 1 | 101 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
16 | | 1 | 110 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
17 | | 1 | 111 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
18 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/5.DMux8Way/DMux8Way.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/DMux8Way.hdl
5 |
6 | /**
7 | * 8-way demultiplexor:
8 | * {a, b, c, d, e, f, g, h} = {in, 0, 0, 0, 0, 0, 0, 0} if sel == 000
9 | * {0, in, 0, 0, 0, 0, 0, 0} if sel == 001
10 | * etc.
11 | * {0, 0, 0, 0, 0, 0, 0, in} if sel == 111
12 | */
13 |
14 | CHIP DMux8Way {
15 | IN in, sel[3];
16 | OUT a, b, c, d, e, f, g, h;
17 |
18 | PARTS:
19 | DMux4Way(in=in, sel=sel[0..1], a=dmux000, b=dmux001, c=dmux010, d=dmux011);
20 | DMux4Way(in=in, sel=sel[0..1], a=dmux100, b=dmux101, c=dmux110, d=dmux111);
21 | Not(in=sel[2], out=notsel2);
22 | And(a=notsel2, b=dmux000, out=a);
23 | And(a=notsel2, b=dmux001, out=b);
24 | And(a=notsel2, b=dmux010, out=c);
25 | And(a=notsel2, b=dmux011, out=d);
26 | And(a=sel[2], b=dmux100, out=e);
27 | And(a=sel[2], b=dmux101, out=f);
28 | And(a=sel[2], b=dmux110, out=g);
29 | And(a=sel[2], b=dmux111, out=h);
30 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/Registers/Register.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/03/a/Register.hdl
5 |
6 | /**
7 | * 16-bit register:
8 | * If load[t] == 1 then out[t+1] = in[t]
9 | * else out does not change
10 | */
11 |
12 | CHIP Register {
13 | IN in[16], load;
14 | OUT out[16];
15 |
16 | PARTS:
17 | Bit(in=in[0], load=load, out=out[0]);
18 | Bit(in=in[1], load=load, out=out[1]);
19 | Bit(in=in[2], load=load, out=out[2]);
20 | Bit(in=in[3], load=load, out=out[3]);
21 | Bit(in=in[4], load=load, out=out[4]);
22 | Bit(in=in[5], load=load, out=out[5]);
23 | Bit(in=in[6], load=load, out=out[6]);
24 | Bit(in=in[7], load=load, out=out[7]);
25 | Bit(in=in[8], load=load, out=out[8]);
26 | Bit(in=in[9], load=load, out=out[9]);
27 | Bit(in=in[10], load=load, out=out[10]);
28 | Bit(in=in[11], load=load, out=out[11]);
29 | Bit(in=in[12], load=load, out=out[12]);
30 | Bit(in=in[13], load=load, out=out[13]);
31 | Bit(in=in[14], load=load, out=out[14]);
32 | Bit(in=in[15], load=load, out=out[15]);
33 | }
34 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/5.DMux8Way/DMux8Way.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/DMux8Way.tst
5 |
6 | load DMux8Way.hdl,
7 | output-file DMux8Way.out,
8 | compare-to DMux8Way.cmp,
9 | output-list in%B2.1.2 sel%B2.3.2 a%B2.1.2 b%B2.1.2 c%B2.1.2 d%B2.1.2 e%B2.1.2 f%B2.1.2 g%B2.1.2 h%B2.1.2;
10 |
11 | set in 0,
12 | set sel %B000,
13 | eval,
14 | output;
15 |
16 | set sel %B001,
17 | eval,
18 | output;
19 |
20 | set sel %B010,
21 | eval,
22 | output;
23 |
24 | set sel %B011,
25 | eval,
26 | output;
27 |
28 | set sel %B100,
29 | eval,
30 | output;
31 |
32 | set sel %B101,
33 | eval,
34 | output;
35 |
36 | set sel %B110,
37 | eval,
38 | output;
39 |
40 | set sel %B111,
41 | eval,
42 | output;
43 |
44 | set in 1,
45 | set sel %B000,
46 | eval,
47 | output;
48 |
49 | set sel %B001,
50 | eval,
51 | output;
52 |
53 | set sel %B010,
54 | eval,
55 | output;
56 |
57 | set sel %B011,
58 | eval,
59 | output;
60 |
61 | set sel %B100,
62 | eval,
63 | output;
64 |
65 | set sel %B101,
66 | eval,
67 | output;
68 |
69 | set sel %B110,
70 | eval,
71 | output;
72 |
73 | set sel %B111,
74 | eval,
75 | output;
76 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/RAMn/RAM8.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/03/a/RAM8.hdl
5 |
6 | /**
7 | * Memory of 8 registers, each 16 bit-wide. Out holds the value
8 | * stored at the memory location specified by address. If load==1, then
9 | * the in value is loaded into the memory location specified by address
10 | * (the loaded value will be emitted to out from the next time step onward).
11 | */
12 |
13 | CHIP RAM8 {
14 | IN in[16], load, address[3];
15 | OUT out[16];
16 |
17 | PARTS:
18 | DMux8Way(in=load ,sel=address ,a=reg0load ,b=reg1load ,c=reg2load ,d=reg3load ,e=reg4load ,f=reg5load ,g=reg6load ,h=reg7load);
19 | Register(in=in ,load=reg0load ,out=reg0out);
20 | Register(in=in ,load=reg1load ,out=reg1out);
21 | Register(in=in ,load=reg2load ,out=reg2out);
22 | Register(in=in ,load=reg3load ,out=reg3out);
23 | Register(in=in ,load=reg4load ,out=reg4out);
24 | Register(in=in ,load=reg5load ,out=reg5out);
25 | Register(in=in ,load=reg6load ,out=reg6out);
26 | Register(in=in ,load=reg7load ,out=reg7out);
27 | Mux8Way16(a=reg0out ,b=reg1out ,c=reg2out ,d=reg3out ,e=reg4out ,f=reg5out ,g=reg6out ,h=reg7out ,sel=address ,out=out);
28 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/16-bit variants/4. MUX16/Mux16.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Mux16.hdl
5 |
6 | /**
7 | * 16-bit multiplexor:
8 | * for i = 0..15 out[i] = a[i] if sel == 0
9 | * b[i] if sel == 1
10 | */
11 |
12 | CHIP Mux16 {
13 | IN a[16], b[16], sel;
14 | OUT out[16];
15 |
16 | PARTS:
17 | Mux(a=a[0], b=b[0], sel=sel, out=out[0]);
18 | Mux(a=a[1], b=b[1], sel=sel, out=out[1]);
19 | Mux(a=a[2], b=b[2], sel=sel, out=out[2]);
20 | Mux(a=a[3], b=b[3], sel=sel, out=out[3]);
21 | Mux(a=a[4], b=b[4], sel=sel, out=out[4]);
22 | Mux(a=a[5], b=b[5], sel=sel, out=out[5]);
23 | Mux(a=a[6], b=b[6], sel=sel, out=out[6]);
24 | Mux(a=a[7], b=b[7], sel=sel, out=out[7]);
25 | Mux(a=a[8], b=b[8], sel=sel, out=out[8]);
26 | Mux(a=a[9], b=b[9], sel=sel, out=out[9]);
27 | Mux(a=a[10], b=b[10], sel=sel, out=out[10]);
28 | Mux(a=a[11], b=b[11], sel=sel, out=out[11]);
29 | Mux(a=a[12], b=b[12], sel=sel, out=out[12]);
30 | Mux(a=a[13], b=b[13], sel=sel, out=out[13]);
31 | Mux(a=a[14], b=b[14], sel=sel, out=out[14]);
32 | Mux(a=a[15], b=b[15], sel=sel, out=out[15]);
33 | }
34 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/max-test/ComputerMax-external.out:
--------------------------------------------------------------------------------
1 | | time |reset|RAM16K[0]|RAM16K[1]|RAM16K[2]|
2 | | 0 | 0 | 3 | 5 | 0 |
3 | | 1 | 0 | 3 | 5 | 0 |
4 | | 2 | 0 | 3 | 5 | 0 |
5 | | 3 | 0 | 3 | 5 | 0 |
6 | | 4 | 0 | 3 | 5 | 0 |
7 | | 5 | 0 | 3 | 5 | 0 |
8 | | 6 | 0 | 3 | 5 | 0 |
9 | | 7 | 0 | 3 | 5 | 0 |
10 | | 8 | 0 | 3 | 5 | 0 |
11 | | 9 | 0 | 3 | 5 | 0 |
12 | | 10 | 0 | 3 | 5 | 0 |
13 | | 11 | 0 | 3 | 5 | 0 |
14 | | 12 | 0 | 3 | 5 | 5 |
15 | | 13 | 0 | 3 | 5 | 5 |
16 | | 14 | 0 | 3 | 5 | 5 |
17 | | 15 | 1 | 3 | 5 | 5 |
18 | | 15 | 0 | 23456 | 12345 | 5 |
19 | | 16 | 0 | 23456 | 12345 | 5 |
20 | | 17 | 0 | 23456 | 12345 | 5 |
21 | | 18 | 0 | 23456 | 12345 | 5 |
22 | | 19 | 0 | 23456 | 12345 | 5 |
23 | | 20 | 0 | 23456 | 12345 | 5 |
24 | | 21 | 0 | 23456 | 12345 | 5 |
25 | | 22 | 0 | 23456 | 12345 | 5 |
26 | | 23 | 0 | 23456 | 12345 | 5 |
27 | | 24 | 0 | 23456 | 12345 | 5 |
28 | | 25 | 0 | 23456 | 12345 | 23456 |
29 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/5. Hack Computer/Computer/max-test/ComputerMax-external.cmp:
--------------------------------------------------------------------------------
1 | | time |reset|RAM16K[0]|RAM16K[1]|RAM16K[2]|
2 | | 0 | 0 | 3 | 5 | 0 |
3 | | 1 | 0 | 3 | 5 | 0 |
4 | | 2 | 0 | 3 | 5 | 0 |
5 | | 3 | 0 | 3 | 5 | 0 |
6 | | 4 | 0 | 3 | 5 | 0 |
7 | | 5 | 0 | 3 | 5 | 0 |
8 | | 6 | 0 | 3 | 5 | 0 |
9 | | 7 | 0 | 3 | 5 | 0 |
10 | | 8 | 0 | 3 | 5 | 0 |
11 | | 9 | 0 | 3 | 5 | 0 |
12 | | 10 | 0 | 3 | 5 | 0 |
13 | | 11 | 0 | 3 | 5 | 0 |
14 | | 12 | 0 | 3 | 5 | 5 |
15 | | 13 | 0 | 3 | 5 | 5 |
16 | | 14 | 0 | 3 | 5 | 5 |
17 | | 15 | 1 | 3 | 5 | 5 |
18 | | 15 | 0 | 23456 | 12345 | 5 |
19 | | 16 | 0 | 23456 | 12345 | 5 |
20 | | 17 | 0 | 23456 | 12345 | 5 |
21 | | 18 | 0 | 23456 | 12345 | 5 |
22 | | 19 | 0 | 23456 | 12345 | 5 |
23 | | 20 | 0 | 23456 | 12345 | 5 |
24 | | 21 | 0 | 23456 | 12345 | 5 |
25 | | 22 | 0 | 23456 | 12345 | 5 |
26 | | 23 | 0 | 23456 | 12345 | 5 |
27 | | 24 | 0 | 23456 | 12345 | 5 |
28 | | 25 | 0 | 23456 | 12345 | 23456 |
29 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/Program Counter/PC.out:
--------------------------------------------------------------------------------
1 | | time | in |reset|load | inc | out |
2 | | 0+ | 0 | 0 | 0 | 0 | 0 |
3 | | 1 | 0 | 0 | 0 | 0 | 0 |
4 | | 1+ | 0 | 0 | 0 | 1 | 0 |
5 | | 2 | 0 | 0 | 0 | 1 | 1 |
6 | | 2+ | -32123 | 0 | 0 | 1 | 1 |
7 | | 3 | -32123 | 0 | 0 | 1 | 2 |
8 | | 3+ | -32123 | 0 | 1 | 1 | 2 |
9 | | 4 | -32123 | 0 | 1 | 1 | -32123 |
10 | | 4+ | -32123 | 0 | 0 | 1 | -32123 |
11 | | 5 | -32123 | 0 | 0 | 1 | -32122 |
12 | | 5+ | -32123 | 0 | 0 | 1 | -32122 |
13 | | 6 | -32123 | 0 | 0 | 1 | -32121 |
14 | | 6+ | 12345 | 0 | 1 | 0 | -32121 |
15 | | 7 | 12345 | 0 | 1 | 0 | 12345 |
16 | | 7+ | 12345 | 1 | 1 | 0 | 12345 |
17 | | 8 | 12345 | 1 | 1 | 0 | 0 |
18 | | 8+ | 12345 | 0 | 1 | 1 | 0 |
19 | | 9 | 12345 | 0 | 1 | 1 | 12345 |
20 | | 9+ | 12345 | 1 | 1 | 1 | 12345 |
21 | | 10 | 12345 | 1 | 1 | 1 | 0 |
22 | | 10+ | 12345 | 0 | 0 | 1 | 0 |
23 | | 11 | 12345 | 0 | 0 | 1 | 1 |
24 | | 11+ | 12345 | 1 | 0 | 1 | 1 |
25 | | 12 | 12345 | 1 | 0 | 1 | 0 |
26 | | 12+ | 0 | 0 | 1 | 1 | 0 |
27 | | 13 | 0 | 0 | 1 | 1 | 0 |
28 | | 13+ | 0 | 0 | 0 | 1 | 0 |
29 | | 14 | 0 | 0 | 0 | 1 | 1 |
30 | | 14+ | 22222 | 1 | 0 | 0 | 1 |
31 | | 15 | 22222 | 1 | 0 | 0 | 0 |
32 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/RAMn/RAM64.hdl:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/03/a/RAM64.hdl
5 |
6 | /**
7 | * Memory of 64 registers, each 16 bit-wide. Out holds the value
8 | * stored at the memory location specified by address. If load==1, then
9 | * the in value is loaded into the memory location specified by address
10 | * (the loaded value will be emitted to out from the next time step onward).
11 | */
12 |
13 | CHIP RAM64 {
14 | IN in[16], load, address[6];
15 | OUT out[16];
16 |
17 | PARTS:
18 | DMux8Way(in=load, sel=address[3..5], a=ram80load, b=ram81load, c=ram82load, d=ram83load, e=ram84load, f=ram85load, g=ram86load, h=ram87load);
19 | RAM8(in=in, load=ram80load, address=address[0..2], out=ram80out);
20 | RAM8(in=in, load=ram81load, address=address[0..2], out=ram81out);
21 | RAM8(in=in, load=ram82load, address=address[0..2], out=ram82out);
22 | RAM8(in=in, load=ram83load, address=address[0..2], out=ram83out);
23 | RAM8(in=in, load=ram84load, address=address[0..2], out=ram84out);
24 | RAM8(in=in, load=ram85load, address=address[0..2], out=ram85out);
25 | RAM8(in=in, load=ram86load, address=address[0..2], out=ram86out);
26 | RAM8(in=in, load=ram87load, address=address[0..2], out=ram87out);
27 | Mux8Way16(a=ram80out, b=ram81out, c=ram82out, d=ram83out, e=ram84out, f=ram85out, g=ram86out, h=ram87out, sel=address[3..5], out=out);
28 | }
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/4. Hack Assembly Programming/fill/Fill.hack:
--------------------------------------------------------------------------------
1 | 0000000000010000
2 | 1110101010001000
3 | 0000000000010001
4 | 1110101010001000
5 | 0110000000000000
6 | 1110110000010000
7 | 0100000000000000
8 | 1110010011010000
9 | 0000000000010010
10 | 1110001100001000
11 | 0000000000010011
12 | 1110101010001000
13 | 0000000000010100
14 | 1110101010001000
15 | 0110000000000000
16 | 1111110000010000
17 | 0000000000010000
18 | 1110001100001000
19 | 0000000000010110
20 | 1110001100000010
21 | 0000000000100100
22 | 1110101010000111
23 | 0000000000010001
24 | 1111110000010000
25 | 0000000000100010
26 | 1110001110000100
27 | 0000000000010001
28 | 1110101010001000
29 | 0000000000100010
30 | 1110110000010000
31 | 0000000000010011
32 | 1110001100001000
33 | 0000000000110010
34 | 1110101010000111
35 | 0000000000001100
36 | 1110101010000111
37 | 0000000000010001
38 | 1111110000010000
39 | 0000000000110000
40 | 1110001110000010
41 | 0000000000010001
42 | 1110111111001000
43 | 0000000000110000
44 | 1110110000010000
45 | 0000000000010011
46 | 1110001100001000
47 | 0000000000110010
48 | 1110101010000111
49 | 0000000000001100
50 | 1110101010000111
51 | 0000000000010100
52 | 1111110000010000
53 | 0000000000010010
54 | 1111010011010000
55 | 0000000001000111
56 | 1110001100000010
57 | 0100000000000000
58 | 1110110000010000
59 | 0000000000010100
60 | 1111000010010000
61 | 0000000000010101
62 | 1110001100001000
63 | 0000000000010001
64 | 1111110011010000
65 | 0000000000010101
66 | 1111110000100000
67 | 1110001100001000
68 | 0000000000010100
69 | 1111110111001000
70 | 0000000000110010
71 | 1110101010000111
72 | 0000000000010011
73 | 1111110000100000
74 | 1110101010000111
75 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/3. Mux8Way16/Mux8Way16.tst:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/01/Mux8Way16.tst
5 |
6 | load Mux8Way16.hdl,
7 | output-file Mux8Way16.out,
8 | compare-to Mux8Way16.cmp,
9 | output-list a%B1.16.1 b%B1.16.1 c%B1.16.1 d%B1.16.1 e%B1.16.1 f%B1.16.1 g%B1.16.1 h%B1.16.1 sel%B2.3.2 out%B1.16.1;
10 |
11 | set a 0,
12 | set b 0,
13 | set c 0,
14 | set d 0,
15 | set e 0,
16 | set f 0,
17 | set g 0,
18 | set h 0,
19 | set sel 0,
20 | eval,
21 | output;
22 |
23 | set sel 1,
24 | eval,
25 | output;
26 |
27 | set sel 2,
28 | eval,
29 | output;
30 |
31 | set sel 3,
32 | eval,
33 | output;
34 |
35 | set sel 4,
36 | eval,
37 | output;
38 |
39 | set sel 5,
40 | eval,
41 | output;
42 |
43 | set sel 6,
44 | eval,
45 | output;
46 |
47 | set sel 7,
48 | eval,
49 | output;
50 |
51 | set a %B0001001000110100,
52 | set b %B0010001101000101,
53 | set c %B0011010001010110,
54 | set d %B0100010101100111,
55 | set e %B0101011001111000,
56 | set f %B0110011110001001,
57 | set g %B0111100010011010,
58 | set h %B1000100110101011,
59 | set sel 0,
60 | eval,
61 | output;
62 |
63 | set sel 1,
64 | eval,
65 | output;
66 |
67 | set sel 2,
68 | eval,
69 | output;
70 |
71 | set sel 3,
72 | eval,
73 | output;
74 |
75 | set sel 4,
76 | eval,
77 | output;
78 |
79 | set sel 5,
80 | eval,
81 | output;
82 |
83 | set sel 6,
84 | eval,
85 | output;
86 |
87 | set sel 7,
88 | eval,
89 | output;
90 |
--------------------------------------------------------------------------------
/Hack-Computer-description-in-HDL/4. Hack Assembly Programming/mult/mult.asm:
--------------------------------------------------------------------------------
1 | // This file is part of www.nand2tetris.org
2 | // and the book "The Elements of Computing Systems"
3 | // by Nisan and Schocken, MIT Press.
4 | // File name: projects/04/Mult.asm
5 |
6 | // Multiplies R0 and R1 and stores the result in R2.
7 | // (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2], respectively.)
8 |
9 |
10 | //pseudo-code: multiplication logic example: 4 * 7 = 7 + 7 + 7 + 7 (sum of four sevens)
11 |
12 | // r0 = RAM[0];
13 | // r1 = RAM[1];
14 | // RAM[2] = 0;
15 | // result = 0;
16 | // i = 0;
17 |
18 | // for(i = 0; i
4 |
5 |
11 | This is a personal project which purpose is to learn computer architecture by implementing the Hack Computer.
12 |
3 |
6 |
7 |
8 | Building the Hack Computer
9 |
10 |
13 |
70 |
71 |
72 |
77 |
78 |
79 |
84 |
85 |
86 | 4. The computer will start to run the program that is preloaded in its ROM. After the first four intructions, value 10 gets loaded at RAM's 6th address. The 2 last instructions are there to avoid that the computer runs garbage instructions stored at subsequential ROM addresses, compromising the result of the actual program.
87 |
88 |
93 |
94 |
95 |