├── .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; i0x6000 is invalid. Access to any address in 19 | * the range 0x4000-0x5FFF results in accessing the screen memory 20 | * map. Access to address 0x6000 results in accessing the keyboard 21 | * memory map. The behavior in these addresses is described in the 22 | * Screen and Keyboard chip specifications given in the book. 23 | */ 24 | 25 | CHIP Memory { 26 | IN in[16], load, address[15]; 27 | OUT out[16]; 28 | 29 | PARTS: 30 | DMux(in=load, sel=address[14], a=loada, b=loadb); 31 | RAM16K(in=in, load=loada, address=address[0..13], out=outRam16k); 32 | Screen(in=in, load=loadb, address=address[0..12], out=outScreen); 33 | Keyboard(out=outKeyboard); 34 | Mux16(a=outScreen, b=outKeyboard, sel=address[13], out=outMemoryMap); 35 | Mux16(a=outRam16k, b=outMemoryMap, sel=address[14], out=out); 36 | } -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/Program Counter/PC.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/03/a/PC.tst 5 | 6 | load PC.hdl, 7 | output-file PC.out, 8 | compare-to PC.cmp, 9 | output-list time%S1.4.1 in%D1.6.1 reset%B2.1.2 load%B2.1.2 inc%B2.1.2 out%D1.6.1; 10 | 11 | set in 0, 12 | set reset 0, 13 | set load 0, 14 | set inc 0, 15 | tick, 16 | output; 17 | 18 | tock, 19 | output; 20 | 21 | set inc 1, 22 | tick, 23 | output; 24 | 25 | tock, 26 | output; 27 | 28 | set in -32123, 29 | tick, 30 | output; 31 | 32 | tock, 33 | output; 34 | 35 | set load 1, 36 | tick, 37 | output; 38 | 39 | tock, 40 | output; 41 | 42 | set load 0, 43 | tick, 44 | output; 45 | 46 | tock, 47 | output; 48 | 49 | tick, 50 | output; 51 | 52 | tock, 53 | output; 54 | 55 | set in 12345, 56 | set load 1, 57 | set inc 0, 58 | tick, 59 | output; 60 | 61 | tock, 62 | output; 63 | 64 | set reset 1, 65 | tick, 66 | output; 67 | 68 | tock, 69 | output; 70 | 71 | set reset 0, 72 | set inc 1, 73 | tick, 74 | output; 75 | 76 | tock, 77 | output; 78 | 79 | set reset 1, 80 | tick, 81 | output; 82 | 83 | tock, 84 | output; 85 | 86 | set reset 0, 87 | set load 0, 88 | tick, 89 | output; 90 | 91 | tock, 92 | output; 93 | 94 | set reset 1, 95 | tick, 96 | output; 97 | 98 | tock, 99 | output; 100 | 101 | set in 0, 102 | set reset 0, 103 | set load 1, 104 | tick, 105 | output; 106 | 107 | tock, 108 | output; 109 | 110 | set load 0, 111 | set inc 1, 112 | tick, 113 | output; 114 | 115 | tock, 116 | output; 117 | 118 | set in 22222, 119 | set reset 1, 120 | set inc 0, 121 | tick, 122 | output; 123 | 124 | tock, 125 | output; 126 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/Computer/max-test/ComputerMax.cmp: -------------------------------------------------------------------------------- 1 | | time |reset|ARegister|DRegister|PC[]|RAM16K[0]|RAM16K[1]|RAM16K[2]| 2 | | 0 | 0 | 0 | 0 | 0| 3 | 5 | 0 | 3 | | 1 | 0 | 0 | 0 | 1| 3 | 5 | 0 | 4 | | 2 | 0 | 0 | 3 | 2| 3 | 5 | 0 | 5 | | 3 | 0 | 1 | 3 | 3| 3 | 5 | 0 | 6 | | 4 | 0 | 1 | -2 | 4| 3 | 5 | 0 | 7 | | 5 | 0 | 10 | -2 | 5| 3 | 5 | 0 | 8 | | 6 | 0 | 10 | -2 | 6| 3 | 5 | 0 | 9 | | 7 | 0 | 1 | -2 | 7| 3 | 5 | 0 | 10 | | 8 | 0 | 1 | 5 | 8| 3 | 5 | 0 | 11 | | 9 | 0 | 12 | 5 | 9| 3 | 5 | 0 | 12 | | 10 | 0 | 12 | 5 | 12| 3 | 5 | 0 | 13 | | 11 | 0 | 2 | 5 | 13| 3 | 5 | 0 | 14 | | 12 | 0 | 2 | 5 | 14| 3 | 5 | 5 | 15 | | 13 | 0 | 14 | 5 | 15| 3 | 5 | 5 | 16 | | 14 | 0 | 14 | 5 | 14| 3 | 5 | 5 | 17 | | 15 | 1 | 14 | 5 | 0| 3 | 5 | 5 | 18 | | 15 | 0 | 14 | 5 | 0| 23456 | 12345 | 5 | 19 | | 16 | 0 | 0 | 5 | 1| 23456 | 12345 | 5 | 20 | | 17 | 0 | 0 | 23456 | 2| 23456 | 12345 | 5 | 21 | | 18 | 0 | 1 | 23456 | 3| 23456 | 12345 | 5 | 22 | | 19 | 0 | 1 | 11111 | 4| 23456 | 12345 | 5 | 23 | | 20 | 0 | 10 | 11111 | 5| 23456 | 12345 | 5 | 24 | | 21 | 0 | 10 | 11111 | 10| 23456 | 12345 | 5 | 25 | | 22 | 0 | 0 | 11111 | 11| 23456 | 12345 | 5 | 26 | | 23 | 0 | 0 | 23456 | 12| 23456 | 12345 | 5 | 27 | | 24 | 0 | 2 | 23456 | 13| 23456 | 12345 | 5 | 28 | | 25 | 0 | 2 | 23456 | 14| 23456 | 12345 | 23456 | 29 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/4. Hack Assembly Programming/mult/Mult.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/mult/Mult.tst 5 | 6 | load Mult.hack, 7 | output-file Mult.out, 8 | compare-to Mult.cmp, 9 | output-list RAM[0]%D2.6.2 RAM[1]%D2.6.2 RAM[2]%D2.6.2; 10 | 11 | set RAM[0] 0, // Set test arguments 12 | set RAM[1] 0, 13 | set RAM[2] -1; // Test that program initialized product to 0 14 | repeat 20 { 15 | ticktock; 16 | } 17 | set RAM[0] 0, // Restore arguments in case program used them as loop counter 18 | set RAM[1] 0, 19 | output; 20 | 21 | set PC 0, 22 | set RAM[0] 1, // Set test arguments 23 | set RAM[1] 0, 24 | set RAM[2] -1; // Ensure that program initialized product to 0 25 | repeat 50 { 26 | ticktock; 27 | } 28 | set RAM[0] 1, // Restore arguments in case program used them as loop counter 29 | set RAM[1] 0, 30 | output; 31 | 32 | set PC 0, 33 | set RAM[0] 0, // Set test arguments 34 | set RAM[1] 2, 35 | set RAM[2] -1; // Ensure that program initialized product to 0 36 | repeat 80 { 37 | ticktock; 38 | } 39 | set RAM[0] 0, // Restore arguments in case program used them as loop counter 40 | set RAM[1] 2, 41 | output; 42 | 43 | set PC 0, 44 | set RAM[0] 3, // Set test arguments 45 | set RAM[1] 1, 46 | set RAM[2] -1; // Ensure that program initialized product to 0 47 | repeat 120 { 48 | ticktock; 49 | } 50 | set RAM[0] 3, // Restore arguments in case program used them as loop counter 51 | set RAM[1] 1, 52 | output; 53 | 54 | set PC 0, 55 | set RAM[0] 2, // Set test arguments 56 | set RAM[1] 4, 57 | set RAM[2] -1; // Ensure that program initialized product to 0 58 | repeat 150 { 59 | ticktock; 60 | } 61 | set RAM[0] 2, // Restore arguments in case program used them as loop counter 62 | set RAM[1] 4, 63 | output; 64 | 65 | set PC 0, 66 | set RAM[0] 6, // Set test arguments 67 | set RAM[1] 7, 68 | set RAM[2] -1; // Ensure that program initialized product to 0 69 | repeat 210 { 70 | ticktock; 71 | } 72 | set RAM[0] 6, // Restore arguments in case program used them as loop counter 73 | set RAM[1] 7, 74 | output; 75 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/Registers/Register.out: -------------------------------------------------------------------------------- 1 | | time | in |load | out | 2 | | 0+ | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 0 | 4 | | 1+ | 0 | 1 | 0 | 5 | | 2 | 0 | 1 | 0 | 6 | | 2+ | -32123 | 0 | 0 | 7 | | 3 | -32123 | 0 | 0 | 8 | | 3+ | 11111 | 0 | 0 | 9 | | 4 | 11111 | 0 | 0 | 10 | | 4+ | -32123 | 1 | 0 | 11 | | 5 | -32123 | 1 | -32123 | 12 | | 5+ | -32123 | 1 | -32123 | 13 | | 6 | -32123 | 1 | -32123 | 14 | | 6+ | -32123 | 0 | -32123 | 15 | | 7 | -32123 | 0 | -32123 | 16 | | 7+ | 12345 | 1 | -32123 | 17 | | 8 | 12345 | 1 | 12345 | 18 | | 8+ | 0 | 0 | 12345 | 19 | | 9 | 0 | 0 | 12345 | 20 | | 9+ | 0 | 1 | 12345 | 21 | | 10 | 0 | 1 | 0 | 22 | | 10+ | 1 | 0 | 0 | 23 | | 11 | 1 | 0 | 0 | 24 | | 11+ | 1 | 1 | 0 | 25 | | 12 | 1 | 1 | 1 | 26 | | 12+ | 2 | 0 | 1 | 27 | | 13 | 2 | 0 | 1 | 28 | | 13+ | 2 | 1 | 1 | 29 | | 14 | 2 | 1 | 2 | 30 | | 14+ | 4 | 0 | 2 | 31 | | 15 | 4 | 0 | 2 | 32 | | 15+ | 4 | 1 | 2 | 33 | | 16 | 4 | 1 | 4 | 34 | | 16+ | 8 | 0 | 4 | 35 | | 17 | 8 | 0 | 4 | 36 | | 17+ | 8 | 1 | 4 | 37 | | 18 | 8 | 1 | 8 | 38 | | 18+ | 16 | 0 | 8 | 39 | | 19 | 16 | 0 | 8 | 40 | | 19+ | 16 | 1 | 8 | 41 | | 20 | 16 | 1 | 16 | 42 | | 20+ | 32 | 0 | 16 | 43 | | 21 | 32 | 0 | 16 | 44 | | 21+ | 32 | 1 | 16 | 45 | | 22 | 32 | 1 | 32 | 46 | | 22+ | 64 | 0 | 32 | 47 | | 23 | 64 | 0 | 32 | 48 | | 23+ | 64 | 1 | 32 | 49 | | 24 | 64 | 1 | 64 | 50 | | 24+ | 128 | 0 | 64 | 51 | | 25 | 128 | 0 | 64 | 52 | | 25+ | 128 | 1 | 64 | 53 | | 26 | 128 | 1 | 128 | 54 | | 26+ | 256 | 0 | 128 | 55 | | 27 | 256 | 0 | 128 | 56 | | 27+ | 256 | 1 | 128 | 57 | | 28 | 256 | 1 | 256 | 58 | | 28+ | 512 | 0 | 256 | 59 | | 29 | 512 | 0 | 256 | 60 | | 29+ | 512 | 1 | 256 | 61 | | 30 | 512 | 1 | 512 | 62 | | 30+ | 1024 | 0 | 512 | 63 | | 31 | 1024 | 0 | 512 | 64 | | 31+ | 1024 | 1 | 512 | 65 | | 32 | 1024 | 1 | 1024 | 66 | | 32+ | 2048 | 0 | 1024 | 67 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/Data Memory/Memory.out: -------------------------------------------------------------------------------- 1 | | in |load | address | out | 2 | | -1 | 1 | 000000000000000 | 0 | 3 | | -1 | 1 | 000000000000000 | -1 | 4 | | 9999 | 0 | 000000000000000 | -1 | 5 | | 9999 | 0 | 000000000000000 | -1 | 6 | | 9999 | 0 | 010000000000000 | 0 | 7 | | 9999 | 0 | 100000000000000 | 0 | 8 | | 2222 | 1 | 010000000000000 | 0 | 9 | | 2222 | 1 | 010000000000000 | 2222 | 10 | | 9999 | 0 | 010000000000000 | 2222 | 11 | | 9999 | 0 | 010000000000000 | 2222 | 12 | | 9999 | 0 | 000000000000000 | -1 | 13 | | 9999 | 0 | 100000000000000 | 0 | 14 | | 9999 | 0 | 000000000000001 | 0 | 15 | | 9999 | 0 | 000000000000010 | 0 | 16 | | 9999 | 0 | 000000000000100 | 0 | 17 | | 9999 | 0 | 000000000001000 | 0 | 18 | | 9999 | 0 | 000000000010000 | 0 | 19 | | 9999 | 0 | 000000000100000 | 0 | 20 | | 9999 | 0 | 000000001000000 | 0 | 21 | | 9999 | 0 | 000000010000000 | 0 | 22 | | 9999 | 0 | 000000100000000 | 0 | 23 | | 9999 | 0 | 000001000000000 | 0 | 24 | | 9999 | 0 | 000010000000000 | 0 | 25 | | 9999 | 0 | 000100000000000 | 0 | 26 | | 9999 | 0 | 001000000000000 | 0 | 27 | | 9999 | 0 | 010000000000000 | 2222 | 28 | | 1234 | 1 | 001001000110100 | 0 | 29 | | 1234 | 1 | 001001000110100 | 1234 | 30 | | 1234 | 0 | 010001000110100 | 0 | 31 | | 1234 | 0 | 110001000110100 | 0 | 32 | | 2345 | 1 | 010001101000101 | 0 | 33 | | 2345 | 1 | 010001101000101 | 2345 | 34 | | 2345 | 0 | 000001101000101 | 0 | 35 | | 2345 | 0 | 100001101000101 | 0 | 36 | | 2345 | 0 | 110000000000000 | 75 | 37 | | -1 | 1 | 100111111001111 | -1 | 38 | | -1 | 1 | 101000001001111 | -1 | 39 | | -1 | 1 | 000111111001111 | 0 | 40 | | -1 | 1 | 010111111001111 | 0 | 41 | | -1 | 0 | 100111111001110 | 0 | 42 | | -1 | 0 | 100111111001101 | 0 | 43 | | -1 | 0 | 100111111001011 | 0 | 44 | | -1 | 0 | 100111111000111 | 0 | 45 | | -1 | 0 | 100111111011111 | 0 | 46 | | -1 | 0 | 100111111101111 | 0 | 47 | | -1 | 0 | 100111110001111 | 0 | 48 | | -1 | 0 | 100111101001111 | 0 | 49 | | -1 | 0 | 100111011001111 | 0 | 50 | | -1 | 0 | 100110111001111 | 0 | 51 | | -1 | 0 | 100101111001111 | 0 | 52 | | -1 | 0 | 100011111001111 | 0 | 53 | | -1 | 0 | 101111111001111 | 0 | 54 | | -1 | 0 | 110000000000000 | 89 | 55 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/Data Memory/Memory.cmp: -------------------------------------------------------------------------------- 1 | | in |load | address | out | 2 | | -1 | 1 | 000000000000000 | 0 | 3 | | -1 | 1 | 000000000000000 | -1 | 4 | | 9999 | 0 | 000000000000000 | -1 | 5 | | 9999 | 0 | 000000000000000 | -1 | 6 | | 9999 | 0 | 010000000000000 | 0 | 7 | | 9999 | 0 | 100000000000000 | 0 | 8 | | 2222 | 1 | 010000000000000 | 0 | 9 | | 2222 | 1 | 010000000000000 | 2222 | 10 | | 9999 | 0 | 010000000000000 | 2222 | 11 | | 9999 | 0 | 010000000000000 | 2222 | 12 | | 9999 | 0 | 000000000000000 | -1 | 13 | | 9999 | 0 | 100000000000000 | 0 | 14 | | 9999 | 0 | 000000000000001 | 0 | 15 | | 9999 | 0 | 000000000000010 | 0 | 16 | | 9999 | 0 | 000000000000100 | 0 | 17 | | 9999 | 0 | 000000000001000 | 0 | 18 | | 9999 | 0 | 000000000010000 | 0 | 19 | | 9999 | 0 | 000000000100000 | 0 | 20 | | 9999 | 0 | 000000001000000 | 0 | 21 | | 9999 | 0 | 000000010000000 | 0 | 22 | | 9999 | 0 | 000000100000000 | 0 | 23 | | 9999 | 0 | 000001000000000 | 0 | 24 | | 9999 | 0 | 000010000000000 | 0 | 25 | | 9999 | 0 | 000100000000000 | 0 | 26 | | 9999 | 0 | 001000000000000 | 0 | 27 | | 9999 | 0 | 010000000000000 | 2222 | 28 | | 1234 | 1 | 001001000110100 | 0 | 29 | | 1234 | 1 | 001001000110100 | 1234 | 30 | | 1234 | 0 | 010001000110100 | 0 | 31 | | 1234 | 0 | 110001000110100 | 0 | 32 | | 2345 | 1 | 010001101000101 | 0 | 33 | | 2345 | 1 | 010001101000101 | 2345 | 34 | | 2345 | 0 | 000001101000101 | 0 | 35 | | 2345 | 0 | 100001101000101 | 0 | 36 | | 2345 | 0 | 110000000000000 | 75 | 37 | | -1 | 1 | 100111111001111 | -1 | 38 | | -1 | 1 | 101000001001111 | -1 | 39 | | -1 | 1 | 000111111001111 | 0 | 40 | | -1 | 1 | 010111111001111 | 0 | 41 | | -1 | 0 | 100111111001110 | 0 | 42 | | -1 | 0 | 100111111001101 | 0 | 43 | | -1 | 0 | 100111111001011 | 0 | 44 | | -1 | 0 | 100111111000111 | 0 | 45 | | -1 | 0 | 100111111011111 | 0 | 46 | | -1 | 0 | 100111111101111 | 0 | 47 | | -1 | 0 | 100111110001111 | 0 | 48 | | -1 | 0 | 100111101001111 | 0 | 49 | | -1 | 0 | 100111011001111 | 0 | 50 | | -1 | 0 | 100110111001111 | 0 | 51 | | -1 | 0 | 100101111001111 | 0 | 52 | | -1 | 0 | 100011111001111 | 0 | 53 | | -1 | 0 | 101111111001111 | 0 | 54 | | -1 | 0 | 110000000000000 | 89 | 55 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/ALU/ALU.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/ALU.hdl 5 | 6 | /** 7 | * The ALU (Arithmetic Logic Unit). 8 | * Computes one of the following functions: 9 | * x+y, x-y, y-x, 0, 1, -1, x, y, -x, -y, !x, !y, 10 | * x+1, y+1, x-1, y-1, x&y, x|y on two 16-bit inputs, 11 | * according to 6 input bits denoted zx,nx,zy,ny,f,no. 12 | * In addition, the ALU computes two 1-bit outputs: 13 | * if the ALU output == 0, zr is set to 1; otherwise zr is set to 0; 14 | * if the ALU output < 0, ng is set to 1; otherwise ng is set to 0. 15 | */ 16 | 17 | // Implementation: the ALU logic manipulates the x and y inputs 18 | // and operates on the resulting values, as follows: 19 | // if (zx == 1) set x = 0 // 16-bit constant 20 | // if (nx == 1) set x = !x // bitwise not 21 | // if (zy == 1) set y = 0 // 16-bit constant 22 | // if (ny == 1) set y = !y // bitwise not 23 | // if (f == 1) set out = x + y // integer 2's complement addition 24 | // if (f == 0) set out = x & y // bitwise and 25 | // if (no == 1) set out = !out // bitwise not 26 | // if (out == 0) set zr = 1 27 | // if (out < 0) set ng = 1 28 | 29 | CHIP ALU { 30 | IN 31 | x[16], y[16], // 16-bit inputs 32 | zx, // zero the x input? 33 | nx, // negate the x input? 34 | zy, // zero the y input? 35 | ny, // negate the y input? 36 | f, // compute out = x + y (if 1) or x & y (if 0) 37 | no; // negate the out output? 38 | 39 | OUT 40 | out[16], // 16-bit output 41 | zr, // 1 if (out == 0), 0 otherwise 42 | ng; // 1 if (out < 0), 0 otherwise 43 | 44 | PARTS: 45 | //zx/zy preset: 46 | Mux16(a=x, b=false, sel=zx, out=zxpreset); 47 | Mux16(a=y, b=false, sel=zy, out=zypreset); 48 | 49 | //nx/ny preset: 50 | Not16(in=zxpreset, out=notzxpreset); 51 | Not16(in=zypreset, out=notzypreset); 52 | Mux16(a=zxpreset, b=notzxpreset, sel=nx, out=nxpreset); 53 | Mux16(a=zypreset, b=notzypreset, sel=ny, out=nypreset); 54 | 55 | //f: 56 | And16(a=nxpreset, b=nypreset, out=andxy); 57 | Add16(a=nxpreset, b=nypreset, out=addxy); 58 | Mux16(a=andxy, b=addxy, sel=f, out=fresult); 59 | 60 | //no: 61 | Not16(in=fresult, out=notfresult); 62 | Mux16(a=fresult, b=notfresult, sel=no, out=out, out[15]=ng, out[0..7]=outLsb, out[8..15]=outMsb); 63 | 64 | //zr: 65 | Or8Way(in=outLsb, out=oroutLsb); 66 | Or8Way(in=outMsb, out=oroutMsb); 67 | Or(a=oroutLsb, b=oroutMsb, out=orout); 68 | Not(in=orout, out=zr); 69 | } -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/3. Mux8Way16/Mux8Way16.out: -------------------------------------------------------------------------------- 1 | | a | b | c | d | e | f | g | h | sel | out | 2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 000 | 0000000000000000 | 3 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 001 | 0000000000000000 | 4 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 010 | 0000000000000000 | 5 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 011 | 0000000000000000 | 6 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 100 | 0000000000000000 | 7 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 101 | 0000000000000000 | 8 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 110 | 0000000000000000 | 9 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 111 | 0000000000000000 | 10 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 000 | 0001001000110100 | 11 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 001 | 0010001101000101 | 12 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 010 | 0011010001010110 | 13 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 011 | 0100010101100111 | 14 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 100 | 0101011001111000 | 15 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 101 | 0110011110001001 | 16 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 110 | 0111100010011010 | 17 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 111 | 1000100110101011 | 18 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/1. Elementary chipset (combinational chips)/multi-way variants/3. Mux8Way16/Mux8Way16.cmp: -------------------------------------------------------------------------------- 1 | | a | b | c | d | e | f | g | h | sel | out | 2 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 000 | 0000000000000000 | 3 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 001 | 0000000000000000 | 4 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 010 | 0000000000000000 | 5 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 011 | 0000000000000000 | 6 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 100 | 0000000000000000 | 7 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 101 | 0000000000000000 | 8 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 110 | 0000000000000000 | 9 | | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 0000000000000000 | 111 | 0000000000000000 | 10 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 000 | 0001001000110100 | 11 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 001 | 0010001101000101 | 12 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 010 | 0011010001010110 | 13 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 011 | 0100010101100111 | 14 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 100 | 0101011001111000 | 15 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 101 | 0110011110001001 | 16 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 110 | 0111100010011010 | 17 | | 0001001000110100 | 0010001101000101 | 0011010001010110 | 0100010101100111 | 0101011001111000 | 0110011110001001 | 0111100010011010 | 1000100110101011 | 111 | 1000100110101011 | 18 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/ALU/ALU.out: -------------------------------------------------------------------------------- 1 | | x | y |zx |nx |zy |ny | f |no | out |zr |ng | 2 | | 0000000000000000 | 1111111111111111 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 | 3 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 | 4 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 | 5 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000000000 | 1 | 0 | 6 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 0 | 1111111111111111 | 0 | 1 | 7 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111111111 | 0 | 1 | 8 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 1 | 0000000000000000 | 1 | 0 | 9 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 1 | 0000000000000000 | 1 | 0 | 10 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 | 0 | 0 | 11 | | 0000000000000000 | 1111111111111111 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 | 12 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000000 | 1 | 0 | 13 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 0 | 1111111111111111 | 0 | 1 | 14 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 0 | 1111111111111110 | 0 | 1 | 15 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 | 16 | | 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 | 0 | 0 | 17 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111111111 | 0 | 1 | 18 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000000 | 1 | 0 | 19 | | 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 1 | 0 | 1 | 1111111111111111 | 0 | 1 | 20 | | 0000000000010001 | 0000000000000011 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 | 21 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 | 22 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 | 23 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000010001 | 0 | 0 | 24 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 0 | 0 | 0000000000000011 | 0 | 0 | 25 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111101110 | 0 | 1 | 26 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 0 | 1 | 1111111111111100 | 0 | 1 | 27 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 1 | 1 | 1111111111101111 | 0 | 1 | 28 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 1 | 1 | 1111111111111101 | 0 | 1 | 29 | | 0000000000010001 | 0000000000000011 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000010010 | 0 | 0 | 30 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000100 | 0 | 0 | 31 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 1 | 0 | 0000000000010000 | 0 | 0 | 32 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 1 | 0 | 0000000000000010 | 0 | 0 | 33 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 0 | 1 | 0 | 0000000000010100 | 0 | 0 | 34 | | 0000000000010001 | 0000000000000011 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000001110 | 0 | 0 | 35 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111110010 | 0 | 1 | 36 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000001 | 0 | 0 | 37 | | 0000000000010001 | 0000000000000011 | 0 | 1 | 0 | 1 | 0 | 1 | 0000000000010011 | 0 | 0 | 38 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/ALU/ALU.cmp: -------------------------------------------------------------------------------- 1 | | x | y |zx |nx |zy |ny | f |no | out |zr |ng | 2 | | 0000000000000000 | 1111111111111111 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 | 3 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 | 4 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 | 5 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000000000 | 1 | 0 | 6 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 0 | 1111111111111111 | 0 | 1 | 7 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111111111 | 0 | 1 | 8 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 1 | 0000000000000000 | 1 | 0 | 9 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 1 | 0000000000000000 | 1 | 0 | 10 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 | 0 | 0 | 11 | | 0000000000000000 | 1111111111111111 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 | 12 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000000 | 1 | 0 | 13 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 0 | 1111111111111111 | 0 | 1 | 14 | | 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 0 | 1111111111111110 | 0 | 1 | 15 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 | 16 | | 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 | 0 | 0 | 17 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111111111 | 0 | 1 | 18 | | 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000000 | 1 | 0 | 19 | | 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 1 | 0 | 1 | 1111111111111111 | 0 | 1 | 20 | | 0000000000010001 | 0000000000000011 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 | 21 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 | 22 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 | 23 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000010001 | 0 | 0 | 24 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 0 | 0 | 0000000000000011 | 0 | 0 | 25 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111101110 | 0 | 1 | 26 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 0 | 1 | 1111111111111100 | 0 | 1 | 27 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 1 | 1 | 1111111111101111 | 0 | 1 | 28 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 1 | 1 | 1111111111111101 | 0 | 1 | 29 | | 0000000000010001 | 0000000000000011 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000010010 | 0 | 0 | 30 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000100 | 0 | 0 | 31 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 1 | 0 | 0000000000010000 | 0 | 0 | 32 | | 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 1 | 0 | 0000000000000010 | 0 | 0 | 33 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 0 | 1 | 0 | 0000000000010100 | 0 | 0 | 34 | | 0000000000010001 | 0000000000000011 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000001110 | 0 | 0 | 35 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111110010 | 0 | 1 | 36 | | 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000001 | 0 | 0 | 37 | | 0000000000010001 | 0000000000000011 | 0 | 1 | 0 | 1 | 0 | 1 | 0000000000010011 | 0 | 0 | 38 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/4. Hack Assembly Programming/fill/Fill.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/Fill.asm 5 | 6 | // Runs an infinite loop that listens to the keyboard input. 7 | // When a key is pressed (any key), the program blackens the screen, 8 | // i.e. writes "black" in every pixel; 9 | // the screen should remain fully black as long as the key is pressed. 10 | // When no key is pressed, the program clears the screen, i.e. writes 11 | // "white" in every pixel; 12 | // the screen should remain fully clear as long as no key is pressed. 13 | 14 | //pseudo-code: 15 | 16 | // while(1){ 17 | // 18 | // keyCode = getCurrentPressedKeyCode(keyboard); 19 | // 20 | // if(keyCode == 0 && screenColor == "black"){ 21 | // whitenScreen(screen); 22 | // screenColor = "white"; 23 | // 24 | // }else if(keyCode != 0 && screenColor == "white") { 25 | // blackenScreen(screen); 26 | // screenColor = "black"; 27 | // } 28 | // 29 | // } 30 | 31 | //hack assembly code: 32 | (MAIN) 33 | 34 | //initializing variables: 35 | 36 | @keyCode 37 | M = 0 38 | 39 | @screenColor 40 | M = 0 41 | 42 | @KBD 43 | D = A 44 | @SCREEN 45 | D = D - A 46 | @screenArraySize 47 | M = D 48 | 49 | @fillReturn 50 | M = 0 51 | 52 | (MAIN_LOOP) 53 | 54 | @i 55 | M = 0 56 | 57 | @KBD 58 | D = M 59 | @keyCode 60 | M = D //keyCode = getCurrentPressedKeyCode(keyboard); 61 | 62 | @WHITEN_SCREEN 63 | D;JEQ //if(keyCode == 0) goto WHITEN_SCREEN 64 | 65 | @BLACKEN_SCREEN 66 | 0;JMP //else goto BLACKEN_SCREEN 67 | 68 | 69 | (WHITEN_SCREEN) 70 | 71 | @screenColor 72 | D = M 73 | @WHITEN_SCREEN_END 74 | D-1;JLT //if(screenColor == "white") got WHITEN_SCREEN_END 75 | 76 | @screenColor 77 | M = 0 //screenColor = "white"; 78 | 79 | @WHITEN_SCREEN_END 80 | D = A 81 | @fillReturn 82 | M = D 83 | @FILL_SCREEN 84 | 0;JMP 85 | 86 | (WHITEN_SCREEN_END) 87 | @MAIN_LOOP 88 | 0;JMP 89 | 90 | (BLACKEN_SCREEN) 91 | 92 | @screenColor 93 | D = M 94 | @BLACKEN_SCREEN_END 95 | D-1;JEQ //if(screenColor == "black") got BLACKEN_SCREEN_END 96 | 97 | @screenColor 98 | M = 1 //screenColor = "black"; 99 | 100 | @BLACKEN_SCREEN_END 101 | D = A 102 | @fillReturn 103 | M = D 104 | @FILL_SCREEN 105 | 0;JMP 106 | 107 | (BLACKEN_SCREEN_END) 108 | @MAIN_LOOP 109 | 0;JMP 110 | 111 | 112 | (FILL_SCREEN) 113 | 114 | (FILL_LOOP) 115 | @i 116 | D = M 117 | @screenArraySize 118 | D = D - M 119 | @FILL_END 120 | D;JEQ //if(i == screenArraySize) goto FILL_END 121 | 122 | @SCREEN 123 | D = A 124 | @i 125 | D = D + M 126 | @currentScreenRegister 127 | M = D //currentScreenRegister = SCREEN + i 128 | @screenColor 129 | D = -M 130 | @currentScreenRegister 131 | A = M; 132 | M = D; //SCREEN[i] = screenColor; 133 | 134 | //i++ 135 | @i 136 | M = M + 1 137 | 138 | @FILL_LOOP 139 | 0;JMP 140 | 141 | (FILL_END) 142 | @fillReturn 143 | A = M 144 | 0;JMP -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/Data Memory/Memory.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/Memory.tst 5 | 6 | load Memory.hdl, 7 | output-file Memory.out, 8 | compare-to Memory.cmp, 9 | output-list in%D1.6.1 load%B2.1.2 address%B1.15.1 out%D1.6.1; 10 | 11 | echo "Before you run this script, select the 'Screen' option from the 'View' menu"; 12 | 13 | set in -1, // Set RAM[0] = -1 14 | set load 1, 15 | set address 0, 16 | tick, 17 | output; 18 | tock, 19 | output; 20 | 21 | set in 9999, // RAM[0] holds value 22 | set load 0, 23 | tick, 24 | output; 25 | tock, 26 | output; 27 | 28 | set address %X2000, // Did not also write to upper RAM or Screen 29 | eval, 30 | output; 31 | set address %X4000, 32 | eval, 33 | output; 34 | 35 | set in 2222, // Set RAM[2000] = 2222 36 | set load 1, 37 | set address %X2000, 38 | tick, 39 | output; 40 | tock, 41 | output; 42 | 43 | set in 9999, // RAM[2000] holds value 44 | set load 0, 45 | tick, 46 | output; 47 | tock, 48 | output; 49 | 50 | set address 0, // Did not also write to lower RAM or Screen 51 | eval, 52 | output; 53 | set address %X4000, 54 | eval, 55 | output; 56 | 57 | set load 0, // Low order address bits connected 58 | set address %X0001, eval, output; 59 | set address %X0002, eval, output; 60 | set address %X0004, eval, output; 61 | set address %X0008, eval, output; 62 | set address %X0010, eval, output; 63 | set address %X0020, eval, output; 64 | set address %X0040, eval, output; 65 | set address %X0080, eval, output; 66 | set address %X0100, eval, output; 67 | set address %X0200, eval, output; 68 | set address %X0400, eval, output; 69 | set address %X0800, eval, output; 70 | set address %X1000, eval, output; 71 | set address %X2000, eval, output; 72 | 73 | set address %X1234, // RAM[1234] = 1234 74 | set in 1234, 75 | set load 1, 76 | tick, 77 | output; 78 | tock, 79 | output; 80 | 81 | set load 0, 82 | set address %X2234, // Did not also write to upper RAM or Screen 83 | eval, output; 84 | set address %X6234, 85 | eval, output; 86 | 87 | set address %X2345, // RAM[2345] = 2345 88 | set in 2345, 89 | set load 1, 90 | tick, 91 | output; 92 | tock, 93 | output; 94 | 95 | set load 0, 96 | set address %X0345, // Did not also write to lower RAM or Screen 97 | eval, output; 98 | set address %X4345, 99 | eval, output; 100 | 101 | // Keyboard test 102 | 103 | set address 24576, 104 | echo "Click the Keyboard icon and hold down the 'K' key (uppercase) until you see the next message (it should appear shortly after that) ...", 105 | // It's important to keep holding the key down since if the system is busy, 106 | // the memory will zero itself before being outputted. 107 | 108 | while out <> 75 { 109 | eval, 110 | } 111 | 112 | clear-echo, 113 | output; 114 | 115 | // Screen test 116 | 117 | set load 1, 118 | set in -1, 119 | set address %X4FCF, 120 | tick, 121 | tock, 122 | output, 123 | 124 | set address %X504F, 125 | tick, 126 | tock, 127 | output; 128 | 129 | set address %X0FCF, // Did not also write to lower or upper RAM 130 | eval, 131 | output; 132 | set address %X2FCF, 133 | eval, 134 | output; 135 | 136 | set load 0, // Low order address bits connected 137 | set address %X4FCE, eval, output; 138 | set address %X4FCD, eval, output; 139 | set address %X4FCB, eval, output; 140 | set address %X4FC7, eval, output; 141 | set address %X4FDF, eval, output; 142 | set address %X4FEF, eval, output; 143 | set address %X4F8F, eval, output; 144 | set address %X4F4F, eval, output; 145 | set address %X4ECF, eval, output; 146 | set address %X4DCF, eval, output; 147 | set address %X4BCF, eval, output; 148 | set address %X47CF, eval, output; 149 | set address %X5FCF, eval, output; 150 | 151 | 152 | set load 0, 153 | set address 24576, 154 | echo "Make sure you see ONLY two horizontal lines in the middle of the screen. Hold down 'Y' (uppercase) until you see the next message ...", 155 | // It's important to keep holding the key down since if the system is busy, 156 | // the memory will zero itself before being outputted. 157 | 158 | while out <> 89 { 159 | eval, 160 | } 161 | 162 | clear-echo, 163 | output; 164 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/Computer/rect-test/ComputerRect.cmp: -------------------------------------------------------------------------------- 1 | | time |ARegister|DRegister|PC[]|RAM16K[0]|RAM16K[1]|RAM16K[2]| 2 | | 0 | 0 | 0 | 0| 4 | 0 | 0 | 3 | | 1 | 0 | 0 | 1| 4 | 0 | 0 | 4 | | 2 | 0 | 4 | 2| 4 | 0 | 0 | 5 | | 3 | 23 | 4 | 3| 4 | 0 | 0 | 6 | | 4 | 23 | 4 | 4| 4 | 0 | 0 | 7 | | 5 | 16 | 4 | 5| 4 | 0 | 0 | 8 | | 6 | 16 | 4 | 6| 4 | 0 | 0 | 9 | | 7 | 16384 | 4 | 7| 4 | 0 | 0 | 10 | | 8 | 16384 | 16384 | 8| 4 | 0 | 0 | 11 | | 9 | 17 | 16384 | 9| 4 | 0 | 0 | 12 | | 10 | 17 | 16384 | 10| 4 | 0 | 0 | 13 | | 11 | 17 | 16384 | 11| 4 | 0 | 0 | 14 | | 12 | 16384 | 16384 | 12| 4 | 0 | 0 | 15 | | 13 | 16384 | 16384 | 13| 4 | 0 | 0 | 16 | | 14 | 17 | 16384 | 14| 4 | 0 | 0 | 17 | | 15 | 17 | 16384 | 15| 4 | 0 | 0 | 18 | | 16 | 32 | 16384 | 16| 4 | 0 | 0 | 19 | | 17 | 32 | 16416 | 17| 4 | 0 | 0 | 20 | | 18 | 17 | 16416 | 18| 4 | 0 | 0 | 21 | | 19 | 17 | 16416 | 19| 4 | 0 | 0 | 22 | | 20 | 16 | 16416 | 20| 4 | 0 | 0 | 23 | | 21 | 16 | 3 | 21| 4 | 0 | 0 | 24 | | 22 | 10 | 3 | 22| 4 | 0 | 0 | 25 | | 23 | 10 | 3 | 10| 4 | 0 | 0 | 26 | | 24 | 17 | 3 | 11| 4 | 0 | 0 | 27 | | 25 | 16416 | 3 | 12| 4 | 0 | 0 | 28 | | 26 | 16416 | 3 | 13| 4 | 0 | 0 | 29 | | 27 | 17 | 3 | 14| 4 | 0 | 0 | 30 | | 28 | 17 | 16416 | 15| 4 | 0 | 0 | 31 | | 29 | 32 | 16416 | 16| 4 | 0 | 0 | 32 | | 30 | 32 | 16448 | 17| 4 | 0 | 0 | 33 | | 31 | 17 | 16448 | 18| 4 | 0 | 0 | 34 | | 32 | 17 | 16448 | 19| 4 | 0 | 0 | 35 | | 33 | 16 | 16448 | 20| 4 | 0 | 0 | 36 | | 34 | 16 | 2 | 21| 4 | 0 | 0 | 37 | | 35 | 10 | 2 | 22| 4 | 0 | 0 | 38 | | 36 | 10 | 2 | 10| 4 | 0 | 0 | 39 | | 37 | 17 | 2 | 11| 4 | 0 | 0 | 40 | | 38 | 16448 | 2 | 12| 4 | 0 | 0 | 41 | | 39 | 16448 | 2 | 13| 4 | 0 | 0 | 42 | | 40 | 17 | 2 | 14| 4 | 0 | 0 | 43 | | 41 | 17 | 16448 | 15| 4 | 0 | 0 | 44 | | 42 | 32 | 16448 | 16| 4 | 0 | 0 | 45 | | 43 | 32 | 16480 | 17| 4 | 0 | 0 | 46 | | 44 | 17 | 16480 | 18| 4 | 0 | 0 | 47 | | 45 | 17 | 16480 | 19| 4 | 0 | 0 | 48 | | 46 | 16 | 16480 | 20| 4 | 0 | 0 | 49 | | 47 | 16 | 1 | 21| 4 | 0 | 0 | 50 | | 48 | 10 | 1 | 22| 4 | 0 | 0 | 51 | | 49 | 10 | 1 | 10| 4 | 0 | 0 | 52 | | 50 | 17 | 1 | 11| 4 | 0 | 0 | 53 | | 51 | 16480 | 1 | 12| 4 | 0 | 0 | 54 | | 52 | 16480 | 1 | 13| 4 | 0 | 0 | 55 | | 53 | 17 | 1 | 14| 4 | 0 | 0 | 56 | | 54 | 17 | 16480 | 15| 4 | 0 | 0 | 57 | | 55 | 32 | 16480 | 16| 4 | 0 | 0 | 58 | | 56 | 32 | 16512 | 17| 4 | 0 | 0 | 59 | | 57 | 17 | 16512 | 18| 4 | 0 | 0 | 60 | | 58 | 17 | 16512 | 19| 4 | 0 | 0 | 61 | | 59 | 16 | 16512 | 20| 4 | 0 | 0 | 62 | | 60 | 16 | 0 | 21| 4 | 0 | 0 | 63 | | 61 | 10 | 0 | 22| 4 | 0 | 0 | 64 | | 62 | 10 | 0 | 23| 4 | 0 | 0 | 65 | | 63 | 23 | 0 | 24| 4 | 0 | 0 | 66 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/CPU/CPU.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/CPU.hdl 5 | 6 | /** 7 | * The Hack CPU (Central Processing unit), consisting of an ALU, 8 | * two registers named A and D, and a program counter named PC. 9 | * The CPU is designed to fetch and execute instructions written in 10 | * the Hack machine language. In particular, functions as follows: 11 | * Executes the inputted instruction according to the Hack machine 12 | * language specification. The D and A in the language specification 13 | * refer to CPU-resident registers, while M refers to the external 14 | * memory location addressed by A, i.e. to Memory[A]. The inM input 15 | * holds the value of this location. If the current instruction needs 16 | * to write a value to M, the value is placed in outM, the address 17 | * of the target location is placed in the addressM output, and the 18 | * writeM control bit is asserted. (When writeM==0, any value may 19 | * appear in outM). The outM and writeM outputs are combinational: 20 | * they are affected instantaneously by the execution of the current 21 | * instruction. The addressM and pc outputs are clocked: although they 22 | * are affected by the execution of the current instruction, they commit 23 | * to their new values only in the next time step. If reset==1 then the 24 | * CPU jumps to address 0 (i.e. pc is set to 0 in next time step) rather 25 | * than to the address resulting from executing the current instruction. 26 | */ 27 | 28 | /* instruction parts: 29 | * C-type A-type 30 | * [15] 1 0 31 | * [14] 1 v1 32 | * [13] 1 ... 33 | * [12] a 34 | * [11] c1 35 | * [10] c2 36 | * [9] c3 37 | * [8] c4 38 | * [7] c5 39 | * [6] c6 40 | * [5] d1 41 | * [4] d2 42 | * [3] d3 43 | * [2] j1 44 | * [1] j2 ... 45 | * [0] j3 v15 46 | */ 47 | CHIP CPU { 48 | 49 | IN inM[16], // M value input (M = contents of RAM[A]) 50 | instruction[16], // Instruction for execution 51 | reset; // Signals whether to re-start the current 52 | // program (reset==1) or continue executing 53 | // the current program (reset==0). 54 | 55 | OUT outM[16], // M value output 56 | writeM, // Write to M? 57 | addressM[15], // Address in data memory (of M) 58 | pc[15]; // address of next instruction 59 | 60 | PARTS: 61 | //A register: 62 | Mux16(a=instruction, b=aluOutput, sel=instruction[15], out=instructionMuxaluOutput); 63 | Mux(a=true, b=instruction[5], sel=instruction[15], out=d1Mux1); 64 | ARegister(in=instructionMuxaluOutput, load=d1Mux1, out=Aout, out[0..14]=addressM); 65 | 66 | //Alu y input: 67 | Mux16(a=Aout, b=inM, sel=instruction[12], out=AmuxM); 68 | 69 | //Alu x input (D register): 70 | Mux(a=false, b=instruction[4], sel=instruction[15], out=d2Mux0); 71 | DRegister(in=aluOutput, load=d2Mux0, out=Dout); 72 | 73 | //Alu: 74 | ALU(x=Dout, y=AmuxM, zx=instruction[11], nx=instruction[10], zy=instruction[9], ny=instruction[8], f=instruction[7], no=instruction[6], out=aluOutput, out=outM, zr=aluZero, ng=aluNegative); 75 | Not(in=aluZero, out=notAluZero); 76 | Not(in=aluNegative, out=notAluNegative); 77 | 78 | Mux(a=false, b=instruction[3], sel=instruction[15], out=writeM); 79 | 80 | //jump logic: 81 | And(a=notAluNegative, b=notAluZero, out=notNgAndnotZr); 82 | And(a=instruction[0], b=notNgAndnotZr, out=j3AndnotNgAndnotZr); 83 | 84 | And(a=notAluNegative, b=aluZero, out=notNgAndzr); 85 | And(a=instruction[1], b=notNgAndzr, out=j2AndnotNgAndzr); 86 | 87 | And(a=aluNegative, b=notAluZero, out=ngAndnotZr); 88 | And(a=instruction[2], b=ngAndnotZr, out=j1AndngAndnotZr); 89 | 90 | Or(a=j3AndnotNgAndnotZr, b=j2AndnotNgAndzr, out=j3Orj2); 91 | Or(a=j3Orj2, b=j1AndngAndnotZr, out=j3Orj2Orj1); 92 | 93 | Mux(a=false, b=j3Orj2Orj1, sel=instruction[15], out=pcLoad); 94 | 95 | //program counter: 96 | PC(in=Aout, load=pcLoad, inc=true, reset=reset, out[0..14]=pc); 97 | 98 | } -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/CPU/CPU.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/CPU.tst 5 | 6 | load CPU.hdl, 7 | output-file CPU.out, 8 | compare-to CPU.cmp, 9 | output-list time%S0.4.0 inM%D0.6.0 instruction%B0.16.0 reset%B2.1.2 outM%D1.6.0 writeM%B3.1.3 addressM%D0.5.0 pc%D0.5.0 DRegister[]%D1.6.1; 10 | 11 | 12 | set instruction %B0011000000111001, // @12345 13 | tick, output, tock, output; 14 | 15 | set instruction %B1110110000010000, // D=A 16 | tick, output, tock, output; 17 | 18 | set instruction %B0101101110100000, // @23456 19 | tick, output, tock, output; 20 | 21 | set instruction %B1110000111010000, // D=A-D 22 | tick, output, tock, output; 23 | 24 | set instruction %B0000001111101000, // @1000 25 | tick, output, tock, output; 26 | 27 | set instruction %B1110001100001000, // M=D 28 | tick, output, tock, output; 29 | 30 | set instruction %B0000001111101001, // @1001 31 | tick, output, tock, output; 32 | 33 | set instruction %B1110001110011000, // MD=D-1 34 | tick, output, tock, output; 35 | 36 | set instruction %B0000001111101000, // @1000 37 | tick, output, tock, output; 38 | 39 | set instruction %B1111010011010000, // D=D-M 40 | set inM 11111, 41 | tick, output, tock, output; 42 | 43 | set instruction %B0000000000001110, // @14 44 | tick, output, tock, output; 45 | 46 | set instruction %B1110001100000100, // D;jlt 47 | tick, output, tock, output; 48 | 49 | set instruction %B0000001111100111, // @999 50 | tick, output, tock, output; 51 | 52 | set instruction %B1110110111100000, // A=A+1 53 | tick, output, tock, output; 54 | 55 | set instruction %B1110001100001000, // M=D 56 | tick, output, tock, output; 57 | 58 | set instruction %B0000000000010101, // @21 59 | tick, output, tock, output; 60 | 61 | set instruction %B1110011111000010, // D+1;jeq 62 | tick, output, tock, output; 63 | 64 | set instruction %B0000000000000010, // @2 65 | tick, output, tock, output; 66 | 67 | set instruction %B1110000010010000, // D=D+A 68 | tick, output, tock, output; 69 | 70 | set instruction %B0000001111101000, // @1000 71 | tick, output, tock, output; 72 | 73 | set instruction %B1110111010010000, // D=-1 74 | tick, output, tock, output; 75 | 76 | set instruction %B1110001100000001, // D;JGT 77 | tick, output, tock, output; 78 | 79 | set instruction %B1110001100000010, // D;JEQ 80 | tick, output, tock, output; 81 | 82 | set instruction %B1110001100000011, // D;JGE 83 | tick, output, tock, output; 84 | 85 | set instruction %B1110001100000100, // D;JLT 86 | tick, output, tock, output; 87 | 88 | set instruction %B1110001100000101, // D;JNE 89 | tick, output, tock, output; 90 | 91 | set instruction %B1110001100000110, // D;JLE 92 | tick, output, tock, output; 93 | 94 | set instruction %B1110001100000111, // D;JMP 95 | tick, output, tock, output; 96 | 97 | set instruction %B1110101010010000, // D=0 98 | tick, output, tock, output; 99 | 100 | set instruction %B1110001100000001, // D;JGT 101 | tick, output, tock, output; 102 | 103 | set instruction %B1110001100000010, // D;JEQ 104 | tick, output, tock, output; 105 | 106 | set instruction %B1110001100000011, // D;JGE 107 | tick, output, tock, output; 108 | 109 | set instruction %B1110001100000100, // D;JLT 110 | tick, output, tock, output; 111 | 112 | set instruction %B1110001100000101, // D;JNE 113 | tick, output, tock, output; 114 | 115 | set instruction %B1110001100000110, // D;JLE 116 | tick, output, tock, output; 117 | 118 | set instruction %B1110001100000111, // D;JMP 119 | tick, output, tock, output; 120 | 121 | set instruction %B1110111111010000, // D=1 122 | tick, output, tock, output; 123 | 124 | set instruction %B1110001100000001, // D;JGT 125 | tick, output, tock, output; 126 | 127 | set instruction %B1110001100000010, // D;JEQ 128 | tick, output, tock, output; 129 | 130 | set instruction %B1110001100000011, // D;JGE 131 | tick, output, tock, output; 132 | 133 | set instruction %B1110001100000100, // D;JLT 134 | tick, output, tock, output; 135 | 136 | set instruction %B1110001100000101, // D;JNE 137 | tick, output, tock, output; 138 | 139 | set instruction %B1110001100000110, // D;JLE 140 | tick, output, tock, output; 141 | 142 | set instruction %B1110001100000111, // D;JMP 143 | tick, output, tock, output; 144 | 145 | set reset 1; 146 | tick, output, tock, output; 147 | 148 | set instruction %B0111111111111111, // @32767 149 | set reset 0; 150 | tick, output, tock, output; 151 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/CPU/CPU-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/CPU-external.tst 5 | 6 | load CPU.hdl, 7 | output-file CPU-external.out, 8 | compare-to CPU-external.cmp, 9 | output-list time%S0.4.0 inM%D0.6.0 instruction%B0.16.0 reset%B2.1.2 outM%D1.6.0 writeM%B3.1.3 addressM%D0.5.0 pc%D0.5.0; 10 | 11 | 12 | set instruction %B0011000000111001, // @12345 13 | tick, output, tock, output; 14 | 15 | set instruction %B1110110000010000, // D=A 16 | tick, output, tock, output; 17 | 18 | set instruction %B0101101110100000, // @23456 19 | tick, output, tock, output; 20 | 21 | set instruction %B1110000111010000, // D=A-D 22 | tick, output, tock, output; 23 | 24 | set instruction %B0000001111101000, // @1000 25 | tick, output, tock, output; 26 | 27 | set instruction %B1110001100001000, // M=D 28 | tick, output, tock, output; 29 | 30 | set instruction %B0000001111101001, // @1001 31 | tick, output, tock, output; 32 | 33 | set instruction %B1110001110011000, // MD=D-1 34 | tick, output, tock, output; 35 | 36 | set instruction %B0000001111101000, // @1000 37 | tick, output, tock, output; 38 | 39 | set instruction %B1111010011010000, // D=D-M 40 | set inM 11111, 41 | tick, output, tock, output; 42 | 43 | set instruction %B0000000000001110, // @14 44 | tick, output, tock, output; 45 | 46 | set instruction %B1110001100000100, // D;jlt 47 | tick, output, tock, output; 48 | 49 | set instruction %B0000001111100111, // @999 50 | tick, output, tock, output; 51 | 52 | set instruction %B1110110111100000, // A=A+1 53 | tick, output, tock, output; 54 | 55 | set instruction %B1110001100001000, // M=D 56 | tick, output, tock, output; 57 | 58 | set instruction %B0000000000010101, // @21 59 | tick, output, tock, output; 60 | 61 | set instruction %B1110011111000010, // D+1;jeq 62 | tick, output, tock, output; 63 | 64 | set instruction %B0000000000000010, // @2 65 | tick, output, tock, output; 66 | 67 | set instruction %B1110000010010000, // D=D+A 68 | tick, output, tock, output; 69 | 70 | set instruction %B0000001111101000, // @1000 71 | tick, output, tock, output; 72 | 73 | set instruction %B1110111010010000, // D=-1 74 | tick, output, tock, output; 75 | 76 | set instruction %B1110001100000001, // D;JGT 77 | tick, output, tock, output; 78 | 79 | set instruction %B1110001100000010, // D;JEQ 80 | tick, output, tock, output; 81 | 82 | set instruction %B1110001100000011, // D;JGE 83 | tick, output, tock, output; 84 | 85 | set instruction %B1110001100000100, // D;JLT 86 | tick, output, tock, output; 87 | 88 | set instruction %B1110001100000101, // D;JNE 89 | tick, output, tock, output; 90 | 91 | set instruction %B1110001100000110, // D;JLE 92 | tick, output, tock, output; 93 | 94 | set instruction %B1110001100000111, // D;JMP 95 | tick, output, tock, output; 96 | 97 | set instruction %B1110101010010000, // D=0 98 | tick, output, tock, output; 99 | 100 | set instruction %B1110001100000001, // D;JGT 101 | tick, output, tock, output; 102 | 103 | set instruction %B1110001100000010, // D;JEQ 104 | tick, output, tock, output; 105 | 106 | set instruction %B1110001100000011, // D;JGE 107 | tick, output, tock, output; 108 | 109 | set instruction %B1110001100000100, // D;JLT 110 | tick, output, tock, output; 111 | 112 | set instruction %B1110001100000101, // D;JNE 113 | tick, output, tock, output; 114 | 115 | set instruction %B1110001100000110, // D;JLE 116 | tick, output, tock, output; 117 | 118 | set instruction %B1110001100000111, // D;JMP 119 | tick, output, tock, output; 120 | 121 | set instruction %B1110111111010000, // D=1 122 | tick, output, tock, output; 123 | 124 | set instruction %B1110001100000001, // D;JGT 125 | tick, output, tock, output; 126 | 127 | set instruction %B1110001100000010, // D;JEQ 128 | tick, output, tock, output; 129 | 130 | set instruction %B1110001100000011, // D;JGE 131 | tick, output, tock, output; 132 | 133 | set instruction %B1110001100000100, // D;JLT 134 | tick, output, tock, output; 135 | 136 | set instruction %B1110001100000101, // D;JNE 137 | tick, output, tock, output; 138 | 139 | set instruction %B1110001100000110, // D;JLE 140 | tick, output, tock, output; 141 | 142 | set instruction %B1110001100000111, // D;JMP 143 | tick, output, tock, output; 144 | 145 | set reset 1; 146 | tick, output, tock, output; 147 | 148 | set instruction %B0111111111111111, // @32767 149 | set reset 0; 150 | tick, output, tock, output; 151 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
3 |

4 | 5 | Logo 6 | 7 | 8 |

Building the Hack Computer

9 | 10 |

11 | This is a personal project which purpose is to learn computer architecture by implementing the Hack Computer. 12 |
13 |

14 |

15 | 16 | 17 | 18 |
19 | Table of Contents 20 |
    21 |
  1. 22 | About The Project 23 |
  2. 24 |
  3. 25 | Getting Started 26 | 29 |
  4. 30 |
  5. Usage
  6. 31 |
  7. Contributing
  8. 32 |
  9. Contact
  10. 33 |
34 |
35 | 36 | 37 | 38 | 39 | ## About The Project 40 | 41 | ![hack-computer](Hack-Computer-(Logisim)/Images/hack-computer.png) 42 | 43 | This is a personal project which purpose is to learn computer architecture by implementing the Hack Computer (Noam Nisan and Shimon Schocken. 2008. The Elements of Computing Systems: Building a Modern Computer from First Principles (History of Computing S.). The MIT Press). 44 | 45 | The aforementioned book, a.k.a NandToTetris, aims to take the reader on a journey to build a simple but powerful 16-bit general-purpose computer. It gives you the knowledge and tools to gradually and modularly implement it from the ground up. The reader starts by building elementary logic gates, such as NOT, AND, OR, ..., and goes all the way until high-level applications, as the classic Tetris game, can be run on the computer that has been built. 46 | 47 | I have only read the book until the 5th chapter in which the system hardware is already implemented and ready to run low-level code. Firstly, I have described the computer in a Hardware Description Language (HDL) by following the book instructions [(check out computer description)](./Hack-Computer-description-in-HDL). Then, I have implemented the computer in Logisim, which is an educational software to simulate logic gates [(check out the Logisim project)](./Hack-Computer-(Logisim)). This book is awesome and presents many computer architecture fundamental concepts, I recommend it to everyone interested in computer science. 48 | 49 | 50 | ## Getting Started 51 | 52 | The computer description in HDL can be interpreted and tested by using the software suite provided by the book. But, its implementation in Logisim is a thing that I have done by myself, so let's see how you can get a local copy of that project and run it. 53 | 54 | ### Prerequisites 55 | 56 | 1. Go to [this website](http://www.cburch.com/logisim/download.html) and follow the instructions to install Logisim. 57 | 58 | 2. Clone this repo: 59 | ```sh 60 | git clone https://github.com/VitorgsRuffo/Building-The-Hack-Computer.git 61 | ``` 62 | 63 | 64 | ## Usage 65 | 66 | 1. Open Logisim and inside it open the "hack-computer.circ" file located at "/path/to/repository/Building-The-Hack-Computer/Hack Computer (Logisim)": 67 | 68 | 69 | open 70 | 71 | 72 |
73 | 74 | 2. Click on the Hack Computer chip: 75 | 76 | chip 77 | 78 | 79 |
80 | 81 | 3. Go to the Simulate option on Logisim's menu and enable clock ticks: 82 | 83 | simulate 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 |
89 | 90 | 5. By inspecting RAM chip we can see that the value 10 has actually been loaded at RAM's 6th address. 91 | 92 | ram 93 | 94 | 95 |
96 | 97 | The book's 4th chapter defines the computer machine language. After understanding it you can write machine-level programs, load them into ROM chip and get the computer to run your program. For more information, check out the book. 98 | 99 | 100 | ## Contributing 101 | 102 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 103 | 104 | 1. Fork the Project 105 | 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) 106 | 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) 107 | 4. Push to the Branch (`git push origin feature/AmazingFeature`) 108 | 5. Open a Pull Request 109 | 110 | 111 | 112 | 113 | ## Contact 114 | 115 | Vitor G. S. Ruffo - [LinkedIn](https://www.linkedin.com/in/vitor-ruffo-8211731b6/) - vitor.gs.ruffo@gmail.com 116 | 117 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/Registers/Register.cmp: -------------------------------------------------------------------------------- 1 | | time | in |load | out | 2 | | 0+ | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 0 | 4 | | 1+ | 0 | 1 | 0 | 5 | | 2 | 0 | 1 | 0 | 6 | | 2+ | -32123 | 0 | 0 | 7 | | 3 | -32123 | 0 | 0 | 8 | | 3+ | 11111 | 0 | 0 | 9 | | 4 | 11111 | 0 | 0 | 10 | | 4+ | -32123 | 1 | 0 | 11 | | 5 | -32123 | 1 | -32123 | 12 | | 5+ | -32123 | 1 | -32123 | 13 | | 6 | -32123 | 1 | -32123 | 14 | | 6+ | -32123 | 0 | -32123 | 15 | | 7 | -32123 | 0 | -32123 | 16 | | 7+ | 12345 | 1 | -32123 | 17 | | 8 | 12345 | 1 | 12345 | 18 | | 8+ | 0 | 0 | 12345 | 19 | | 9 | 0 | 0 | 12345 | 20 | | 9+ | 0 | 1 | 12345 | 21 | | 10 | 0 | 1 | 0 | 22 | | 10+ | 1 | 0 | 0 | 23 | | 11 | 1 | 0 | 0 | 24 | | 11+ | 1 | 1 | 0 | 25 | | 12 | 1 | 1 | 1 | 26 | | 12+ | 2 | 0 | 1 | 27 | | 13 | 2 | 0 | 1 | 28 | | 13+ | 2 | 1 | 1 | 29 | | 14 | 2 | 1 | 2 | 30 | | 14+ | 4 | 0 | 2 | 31 | | 15 | 4 | 0 | 2 | 32 | | 15+ | 4 | 1 | 2 | 33 | | 16 | 4 | 1 | 4 | 34 | | 16+ | 8 | 0 | 4 | 35 | | 17 | 8 | 0 | 4 | 36 | | 17+ | 8 | 1 | 4 | 37 | | 18 | 8 | 1 | 8 | 38 | | 18+ | 16 | 0 | 8 | 39 | | 19 | 16 | 0 | 8 | 40 | | 19+ | 16 | 1 | 8 | 41 | | 20 | 16 | 1 | 16 | 42 | | 20+ | 32 | 0 | 16 | 43 | | 21 | 32 | 0 | 16 | 44 | | 21+ | 32 | 1 | 16 | 45 | | 22 | 32 | 1 | 32 | 46 | | 22+ | 64 | 0 | 32 | 47 | | 23 | 64 | 0 | 32 | 48 | | 23+ | 64 | 1 | 32 | 49 | | 24 | 64 | 1 | 64 | 50 | | 24+ | 128 | 0 | 64 | 51 | | 25 | 128 | 0 | 64 | 52 | | 25+ | 128 | 1 | 64 | 53 | | 26 | 128 | 1 | 128 | 54 | | 26+ | 256 | 0 | 128 | 55 | | 27 | 256 | 0 | 128 | 56 | | 27+ | 256 | 1 | 128 | 57 | | 28 | 256 | 1 | 256 | 58 | | 28+ | 512 | 0 | 256 | 59 | | 29 | 512 | 0 | 256 | 60 | | 29+ | 512 | 1 | 256 | 61 | | 30 | 512 | 1 | 512 | 62 | | 30+ | 1024 | 0 | 512 | 63 | | 31 | 1024 | 0 | 512 | 64 | | 31+ | 1024 | 1 | 512 | 65 | | 32 | 1024 | 1 | 1024 | 66 | | 32+ | 2048 | 0 | 1024 | 67 | | 33 | 2048 | 0 | 1024 | 68 | | 33+ | 2048 | 1 | 1024 | 69 | | 34 | 2048 | 1 | 2048 | 70 | | 34+ | 4096 | 0 | 2048 | 71 | | 35 | 4096 | 0 | 2048 | 72 | | 35+ | 4096 | 1 | 2048 | 73 | | 36 | 4096 | 1 | 4096 | 74 | | 36+ | 8192 | 0 | 4096 | 75 | | 37 | 8192 | 0 | 4096 | 76 | | 37+ | 8192 | 1 | 4096 | 77 | | 38 | 8192 | 1 | 8192 | 78 | | 38+ | 16384 | 0 | 8192 | 79 | | 39 | 16384 | 0 | 8192 | 80 | | 39+ | 16384 | 1 | 8192 | 81 | | 40 | 16384 | 1 | 16384 | 82 | | 40+ | -32768 | 0 | 16384 | 83 | | 41 | -32768 | 0 | 16384 | 84 | | 41+ | -32768 | 1 | 16384 | 85 | | 42 | -32768 | 1 | -32768 | 86 | | 42+ | -2 | 0 | -32768 | 87 | | 43 | -2 | 0 | -32768 | 88 | | 43+ | -2 | 1 | -32768 | 89 | | 44 | -2 | 1 | -2 | 90 | | 44+ | -3 | 0 | -2 | 91 | | 45 | -3 | 0 | -2 | 92 | | 45+ | -3 | 1 | -2 | 93 | | 46 | -3 | 1 | -3 | 94 | | 46+ | -5 | 0 | -3 | 95 | | 47 | -5 | 0 | -3 | 96 | | 47+ | -5 | 1 | -3 | 97 | | 48 | -5 | 1 | -5 | 98 | | 48+ | -9 | 0 | -5 | 99 | | 49 | -9 | 0 | -5 | 100 | | 49+ | -9 | 1 | -5 | 101 | | 50 | -9 | 1 | -9 | 102 | | 50+ | -17 | 0 | -9 | 103 | | 51 | -17 | 0 | -9 | 104 | | 51+ | -17 | 1 | -9 | 105 | | 52 | -17 | 1 | -17 | 106 | | 52+ | -33 | 0 | -17 | 107 | | 53 | -33 | 0 | -17 | 108 | | 53+ | -33 | 1 | -17 | 109 | | 54 | -33 | 1 | -33 | 110 | | 54+ | -65 | 0 | -33 | 111 | | 55 | -65 | 0 | -33 | 112 | | 55+ | -65 | 1 | -33 | 113 | | 56 | -65 | 1 | -65 | 114 | | 56+ | -129 | 0 | -65 | 115 | | 57 | -129 | 0 | -65 | 116 | | 57+ | -129 | 1 | -65 | 117 | | 58 | -129 | 1 | -129 | 118 | | 58+ | -257 | 0 | -129 | 119 | | 59 | -257 | 0 | -129 | 120 | | 59+ | -257 | 1 | -129 | 121 | | 60 | -257 | 1 | -257 | 122 | | 60+ | -513 | 0 | -257 | 123 | | 61 | -513 | 0 | -257 | 124 | | 61+ | -513 | 1 | -257 | 125 | | 62 | -513 | 1 | -513 | 126 | | 62+ | -1025 | 0 | -513 | 127 | | 63 | -1025 | 0 | -513 | 128 | | 63+ | -1025 | 1 | -513 | 129 | | 64 | -1025 | 1 | -1025 | 130 | | 64+ | -2049 | 0 | -1025 | 131 | | 65 | -2049 | 0 | -1025 | 132 | | 65+ | -2049 | 1 | -1025 | 133 | | 66 | -2049 | 1 | -2049 | 134 | | 66+ | -4097 | 0 | -2049 | 135 | | 67 | -4097 | 0 | -2049 | 136 | | 67+ | -4097 | 1 | -2049 | 137 | | 68 | -4097 | 1 | -4097 | 138 | | 68+ | -8193 | 0 | -4097 | 139 | | 69 | -8193 | 0 | -4097 | 140 | | 69+ | -8193 | 1 | -4097 | 141 | | 70 | -8193 | 1 | -8193 | 142 | | 70+ | -16385 | 0 | -8193 | 143 | | 71 | -16385 | 0 | -8193 | 144 | | 71+ | -16385 | 1 | -8193 | 145 | | 72 | -16385 | 1 | -16385 | 146 | | 72+ | 32767 | 0 | -16385 | 147 | | 73 | 32767 | 0 | -16385 | 148 | | 73+ | 32767 | 1 | -16385 | 149 | | 74 | 32767 | 1 | 32767 | 150 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/2. Adders and ALU (combinational chips)/ALU/ALU.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/ALU.tst 5 | 6 | load ALU.hdl, 7 | output-file ALU.out, 8 | compare-to ALU.cmp, 9 | output-list x%B1.16.1 y%B1.16.1 zx%B1.1.1 nx%B1.1.1 zy%B1.1.1 10 | ny%B1.1.1 f%B1.1.1 no%B1.1.1 out%B1.16.1 zr%B1.1.1 11 | ng%B1.1.1; 12 | 13 | set x %B0000000000000000, // x = 0 14 | set y %B1111111111111111; // y = -1 15 | 16 | // Compute 0 17 | set zx 1, 18 | set nx 0, 19 | set zy 1, 20 | set ny 0, 21 | set f 1, 22 | set no 0, 23 | eval, 24 | output; 25 | 26 | // Compute 1 27 | set zx 1, 28 | set nx 1, 29 | set zy 1, 30 | set ny 1, 31 | set f 1, 32 | set no 1, 33 | eval, 34 | output; 35 | 36 | // Compute -1 37 | set zx 1, 38 | set nx 1, 39 | set zy 1, 40 | set ny 0, 41 | set f 1, 42 | set no 0, 43 | eval, 44 | output; 45 | 46 | // Compute x 47 | set zx 0, 48 | set nx 0, 49 | set zy 1, 50 | set ny 1, 51 | set f 0, 52 | set no 0, 53 | eval, 54 | output; 55 | 56 | // Compute y 57 | set zx 1, 58 | set nx 1, 59 | set zy 0, 60 | set ny 0, 61 | set f 0, 62 | set no 0, 63 | eval, 64 | output; 65 | 66 | // Compute !x 67 | set zx 0, 68 | set nx 0, 69 | set zy 1, 70 | set ny 1, 71 | set f 0, 72 | set no 1, 73 | eval, 74 | output; 75 | 76 | // Compute !y 77 | set zx 1, 78 | set nx 1, 79 | set zy 0, 80 | set ny 0, 81 | set f 0, 82 | set no 1, 83 | eval, 84 | output; 85 | 86 | // Compute -x 87 | set zx 0, 88 | set nx 0, 89 | set zy 1, 90 | set ny 1, 91 | set f 1, 92 | set no 1, 93 | eval, 94 | output; 95 | 96 | // Compute -y 97 | set zx 1, 98 | set nx 1, 99 | set zy 0, 100 | set ny 0, 101 | set f 1, 102 | set no 1, 103 | eval, 104 | output; 105 | 106 | // Compute x + 1 107 | set zx 0, 108 | set nx 1, 109 | set zy 1, 110 | set ny 1, 111 | set f 1, 112 | set no 1, 113 | eval, 114 | output; 115 | 116 | // Compute y + 1 117 | set zx 1, 118 | set nx 1, 119 | set zy 0, 120 | set ny 1, 121 | set f 1, 122 | set no 1, 123 | eval, 124 | output; 125 | 126 | // Compute x - 1 127 | set zx 0, 128 | set nx 0, 129 | set zy 1, 130 | set ny 1, 131 | set f 1, 132 | set no 0, 133 | eval, 134 | output; 135 | 136 | // Compute y - 1 137 | set zx 1, 138 | set nx 1, 139 | set zy 0, 140 | set ny 0, 141 | set f 1, 142 | set no 0, 143 | eval, 144 | output; 145 | 146 | // Compute x + y 147 | set zx 0, 148 | set nx 0, 149 | set zy 0, 150 | set ny 0, 151 | set f 1, 152 | set no 0, 153 | eval, 154 | output; 155 | 156 | // Compute x - y 157 | set zx 0, 158 | set nx 1, 159 | set zy 0, 160 | set ny 0, 161 | set f 1, 162 | set no 1, 163 | eval, 164 | output; 165 | 166 | // Compute y - x 167 | set zx 0, 168 | set nx 0, 169 | set zy 0, 170 | set ny 1, 171 | set f 1, 172 | set no 1, 173 | eval, 174 | output; 175 | 176 | // Compute x & y 177 | set zx 0, 178 | set nx 0, 179 | set zy 0, 180 | set ny 0, 181 | set f 0, 182 | set no 0, 183 | eval, 184 | output; 185 | 186 | // Compute x | y 187 | set zx 0, 188 | set nx 1, 189 | set zy 0, 190 | set ny 1, 191 | set f 0, 192 | set no 1, 193 | eval, 194 | output; 195 | 196 | set x %B000000000010001, // x = 17 197 | set y %B000000000000011; // y = 3 198 | 199 | // Compute 0 200 | set zx 1, 201 | set nx 0, 202 | set zy 1, 203 | set ny 0, 204 | set f 1, 205 | set no 0, 206 | eval, 207 | output; 208 | 209 | // Compute 1 210 | set zx 1, 211 | set nx 1, 212 | set zy 1, 213 | set ny 1, 214 | set f 1, 215 | set no 1, 216 | eval, 217 | output; 218 | 219 | // Compute -1 220 | set zx 1, 221 | set nx 1, 222 | set zy 1, 223 | set ny 0, 224 | set f 1, 225 | set no 0, 226 | eval, 227 | output; 228 | 229 | // Compute x 230 | set zx 0, 231 | set nx 0, 232 | set zy 1, 233 | set ny 1, 234 | set f 0, 235 | set no 0, 236 | eval, 237 | output; 238 | 239 | // Compute y 240 | set zx 1, 241 | set nx 1, 242 | set zy 0, 243 | set ny 0, 244 | set f 0, 245 | set no 0, 246 | eval, 247 | output; 248 | 249 | // Compute !x 250 | set zx 0, 251 | set nx 0, 252 | set zy 1, 253 | set ny 1, 254 | set f 0, 255 | set no 1, 256 | eval, 257 | output; 258 | 259 | // Compute !y 260 | set zx 1, 261 | set nx 1, 262 | set zy 0, 263 | set ny 0, 264 | set f 0, 265 | set no 1, 266 | eval, 267 | output; 268 | 269 | // Compute -x 270 | set zx 0, 271 | set nx 0, 272 | set zy 1, 273 | set ny 1, 274 | set f 1, 275 | set no 1, 276 | eval, 277 | output; 278 | 279 | // Compute -y 280 | set zx 1, 281 | set nx 1, 282 | set zy 0, 283 | set ny 0, 284 | set f 1, 285 | set no 1, 286 | eval, 287 | output; 288 | 289 | // Compute x + 1 290 | set zx 0, 291 | set nx 1, 292 | set zy 1, 293 | set ny 1, 294 | set f 1, 295 | set no 1, 296 | eval, 297 | output; 298 | 299 | // Compute y + 1 300 | set zx 1, 301 | set nx 1, 302 | set zy 0, 303 | set ny 1, 304 | set f 1, 305 | set no 1, 306 | eval, 307 | output; 308 | 309 | // Compute x - 1 310 | set zx 0, 311 | set nx 0, 312 | set zy 1, 313 | set ny 1, 314 | set f 1, 315 | set no 0, 316 | eval, 317 | output; 318 | 319 | // Compute y - 1 320 | set zx 1, 321 | set nx 1, 322 | set zy 0, 323 | set ny 0, 324 | set f 1, 325 | set no 0, 326 | eval, 327 | output; 328 | 329 | // Compute x + y 330 | set zx 0, 331 | set nx 0, 332 | set zy 0, 333 | set ny 0, 334 | set f 1, 335 | set no 0, 336 | eval, 337 | output; 338 | 339 | // Compute x - y 340 | set zx 0, 341 | set nx 1, 342 | set zy 0, 343 | set ny 0, 344 | set f 1, 345 | set no 1, 346 | eval, 347 | output; 348 | 349 | // Compute y - x 350 | set zx 0, 351 | set nx 0, 352 | set zy 0, 353 | set ny 1, 354 | set f 1, 355 | set no 1, 356 | eval, 357 | output; 358 | 359 | // Compute x & y 360 | set zx 0, 361 | set nx 0, 362 | set zy 0, 363 | set ny 0, 364 | set f 0, 365 | set no 0, 366 | eval, 367 | output; 368 | 369 | // Compute x | y 370 | set zx 0, 371 | set nx 1, 372 | set zy 0, 373 | set ny 1, 374 | set f 0, 375 | set no 1, 376 | eval, 377 | output; 378 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/CPU/CPU-external.out: -------------------------------------------------------------------------------- 1 | |time| inM | instruction |reset| outM |writeM |addre| pc | 2 | |0+ | 0|0011000000111001| 0 | 0| 0 | 0| 0| 3 | |1 | 0|0011000000111001| 0 | 0| 0 |12345| 1| 4 | |1+ | 0|1110110000010000| 0 | 12345| 0 |12345| 1| 5 | |2 | 0|1110110000010000| 0 | 12345| 0 |12345| 2| 6 | |2+ | 0|0101101110100000| 0 | -1| 0 |12345| 2| 7 | |3 | 0|0101101110100000| 0 | -1| 0 |23456| 3| 8 | |3+ | 0|1110000111010000| 0 | 11111| 0 |23456| 3| 9 | |4 | 0|1110000111010000| 0 | 12345| 0 |23456| 4| 10 | |4+ | 0|0000001111101000| 0 | -11111| 0 |23456| 4| 11 | |5 | 0|0000001111101000| 0 | -11111| 0 | 1000| 5| 12 | |5+ | 0|1110001100001000| 0 | 11111| 1 | 1000| 5| 13 | |6 | 0|1110001100001000| 0 | 11111| 1 | 1000| 6| 14 | |6+ | 0|0000001111101001| 0 | -11111| 0 | 1000| 6| 15 | |7 | 0|0000001111101001| 0 | -11111| 0 | 1001| 7| 16 | |7+ | 0|1110001110011000| 0 | 11110| 1 | 1001| 7| 17 | |8 | 0|1110001110011000| 0 | 11109| 1 | 1001| 8| 18 | |8+ | 0|0000001111101000| 0 | -11110| 0 | 1001| 8| 19 | |9 | 0|0000001111101000| 0 | -11110| 0 | 1000| 9| 20 | |9+ | 11111|1111010011010000| 0 | -1| 0 | 1000| 9| 21 | |10 | 11111|1111010011010000| 0 | -11112| 0 | 1000| 10| 22 | |10+ | 11111|0000000000001110| 0 | 1000| 0 | 1000| 10| 23 | |11 | 11111|0000000000001110| 0 | 14| 0 | 14| 11| 24 | |11+ | 11111|1110001100000100| 0 | -1| 0 | 14| 11| 25 | |12 | 11111|1110001100000100| 0 | -1| 0 | 14| 14| 26 | |12+ | 11111|0000001111100111| 0 | 1| 0 | 14| 14| 27 | |13 | 11111|0000001111100111| 0 | 1| 0 | 999| 15| 28 | |13+ | 11111|1110110111100000| 0 | 1000| 0 | 999| 15| 29 | |14 | 11111|1110110111100000| 0 | 1001| 0 | 1000| 16| 30 | |14+ | 11111|1110001100001000| 0 | -1| 1 | 1000| 16| 31 | |15 | 11111|1110001100001000| 0 | -1| 1 | 1000| 17| 32 | |15+ | 11111|0000000000010101| 0 | 1000| 0 | 1000| 17| 33 | |16 | 11111|0000000000010101| 0 | 21| 0 | 21| 18| 34 | |16+ | 11111|1110011111000010| 0 | 0| 0 | 21| 18| 35 | |17 | 11111|1110011111000010| 0 | 0| 0 | 21| 21| 36 | |17+ | 11111|0000000000000010| 0 | 21| 0 | 21| 21| 37 | |18 | 11111|0000000000000010| 0 | 2| 0 | 2| 22| 38 | |18+ | 11111|1110000010010000| 0 | 1| 0 | 2| 22| 39 | |19 | 11111|1110000010010000| 0 | 3| 0 | 2| 23| 40 | |19+ | 11111|0000001111101000| 0 | -1| 0 | 2| 23| 41 | |20 | 11111|0000001111101000| 0 | -1| 0 | 1000| 24| 42 | |20+ | 11111|1110111010010000| 0 | -1| 0 | 1000| 24| 43 | |21 | 11111|1110111010010000| 0 | -1| 0 | 1000| 25| 44 | |21+ | 11111|1110001100000001| 0 | -1| 0 | 1000| 25| 45 | |22 | 11111|1110001100000001| 0 | -1| 0 | 1000| 26| 46 | |22+ | 11111|1110001100000010| 0 | -1| 0 | 1000| 26| 47 | |23 | 11111|1110001100000010| 0 | -1| 0 | 1000| 27| 48 | |23+ | 11111|1110001100000011| 0 | -1| 0 | 1000| 27| 49 | |24 | 11111|1110001100000011| 0 | -1| 0 | 1000| 28| 50 | |24+ | 11111|1110001100000100| 0 | -1| 0 | 1000| 28| 51 | |25 | 11111|1110001100000100| 0 | -1| 0 | 1000| 1000| 52 | |25+ | 11111|1110001100000101| 0 | -1| 0 | 1000| 1000| 53 | |26 | 11111|1110001100000101| 0 | -1| 0 | 1000| 1000| 54 | |26+ | 11111|1110001100000110| 0 | -1| 0 | 1000| 1000| 55 | |27 | 11111|1110001100000110| 0 | -1| 0 | 1000| 1000| 56 | |27+ | 11111|1110001100000111| 0 | -1| 0 | 1000| 1000| 57 | |28 | 11111|1110001100000111| 0 | -1| 0 | 1000| 1000| 58 | |28+ | 11111|1110101010010000| 0 | 0| 0 | 1000| 1000| 59 | |29 | 11111|1110101010010000| 0 | 0| 0 | 1000| 1001| 60 | |29+ | 11111|1110001100000001| 0 | 0| 0 | 1000| 1001| 61 | |30 | 11111|1110001100000001| 0 | 0| 0 | 1000| 1002| 62 | |30+ | 11111|1110001100000010| 0 | 0| 0 | 1000| 1002| 63 | |31 | 11111|1110001100000010| 0 | 0| 0 | 1000| 1000| 64 | |31+ | 11111|1110001100000011| 0 | 0| 0 | 1000| 1000| 65 | |32 | 11111|1110001100000011| 0 | 0| 0 | 1000| 1000| 66 | |32+ | 11111|1110001100000100| 0 | 0| 0 | 1000| 1000| 67 | |33 | 11111|1110001100000100| 0 | 0| 0 | 1000| 1001| 68 | |33+ | 11111|1110001100000101| 0 | 0| 0 | 1000| 1001| 69 | |34 | 11111|1110001100000101| 0 | 0| 0 | 1000| 1002| 70 | |34+ | 11111|1110001100000110| 0 | 0| 0 | 1000| 1002| 71 | |35 | 11111|1110001100000110| 0 | 0| 0 | 1000| 1000| 72 | |35+ | 11111|1110001100000111| 0 | 0| 0 | 1000| 1000| 73 | |36 | 11111|1110001100000111| 0 | 0| 0 | 1000| 1000| 74 | |36+ | 11111|1110111111010000| 0 | 1| 0 | 1000| 1000| 75 | |37 | 11111|1110111111010000| 0 | 1| 0 | 1000| 1001| 76 | |37+ | 11111|1110001100000001| 0 | 1| 0 | 1000| 1001| 77 | |38 | 11111|1110001100000001| 0 | 1| 0 | 1000| 1000| 78 | |38+ | 11111|1110001100000010| 0 | 1| 0 | 1000| 1000| 79 | |39 | 11111|1110001100000010| 0 | 1| 0 | 1000| 1001| 80 | |39+ | 11111|1110001100000011| 0 | 1| 0 | 1000| 1001| 81 | |40 | 11111|1110001100000011| 0 | 1| 0 | 1000| 1000| 82 | |40+ | 11111|1110001100000100| 0 | 1| 0 | 1000| 1000| 83 | |41 | 11111|1110001100000100| 0 | 1| 0 | 1000| 1001| 84 | |41+ | 11111|1110001100000101| 0 | 1| 0 | 1000| 1001| 85 | |42 | 11111|1110001100000101| 0 | 1| 0 | 1000| 1000| 86 | |42+ | 11111|1110001100000110| 0 | 1| 0 | 1000| 1000| 87 | |43 | 11111|1110001100000110| 0 | 1| 0 | 1000| 1001| 88 | |43+ | 11111|1110001100000111| 0 | 1| 0 | 1000| 1001| 89 | |44 | 11111|1110001100000111| 0 | 1| 0 | 1000| 1000| 90 | |44+ | 11111|1110001100000111| 1 | 1| 0 | 1000| 1000| 91 | |45 | 11111|1110001100000111| 1 | 1| 0 | 1000| 0| 92 | |45+ | 11111|0111111111111111| 0 | 1| 0 | 1000| 0| 93 | |46 | 11111|0111111111111111| 0 | 1| 0 |32767| 1| 94 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/CPU/CPU-external.cmp: -------------------------------------------------------------------------------- 1 | |time| inM | instruction |reset| outM |writeM |addre| pc | 2 | |0+ | 0|0011000000111001| 0 |*******| 0 | 0| 0| 3 | |1 | 0|0011000000111001| 0 |*******| 0 |12345| 1| 4 | |1+ | 0|1110110000010000| 0 |*******| 0 |12345| 1| 5 | |2 | 0|1110110000010000| 0 |*******| 0 |12345| 2| 6 | |2+ | 0|0101101110100000| 0 |*******| 0 |12345| 2| 7 | |3 | 0|0101101110100000| 0 |*******| 0 |23456| 3| 8 | |3+ | 0|1110000111010000| 0 |*******| 0 |23456| 3| 9 | |4 | 0|1110000111010000| 0 |*******| 0 |23456| 4| 10 | |4+ | 0|0000001111101000| 0 |*******| 0 |23456| 4| 11 | |5 | 0|0000001111101000| 0 |*******| 0 | 1000| 5| 12 | |5+ | 0|1110001100001000| 0 | 11111| 1 | 1000| 5| 13 | |6 | 0|1110001100001000| 0 | 11111| 1 | 1000| 6| 14 | |6+ | 0|0000001111101001| 0 |*******| 0 | 1000| 6| 15 | |7 | 0|0000001111101001| 0 |*******| 0 | 1001| 7| 16 | |7+ | 0|1110001110011000| 0 | 11110| 1 | 1001| 7| 17 | |8 | 0|1110001110011000| 0 | 11109| 1 | 1001| 8| 18 | |8+ | 0|0000001111101000| 0 |*******| 0 | 1001| 8| 19 | |9 | 0|0000001111101000| 0 |*******| 0 | 1000| 9| 20 | |9+ | 11111|1111010011010000| 0 |*******| 0 | 1000| 9| 21 | |10 | 11111|1111010011010000| 0 |*******| 0 | 1000| 10| 22 | |10+ | 11111|0000000000001110| 0 |*******| 0 | 1000| 10| 23 | |11 | 11111|0000000000001110| 0 |*******| 0 | 14| 11| 24 | |11+ | 11111|1110001100000100| 0 |*******| 0 | 14| 11| 25 | |12 | 11111|1110001100000100| 0 |*******| 0 | 14| 14| 26 | |12+ | 11111|0000001111100111| 0 |*******| 0 | 14| 14| 27 | |13 | 11111|0000001111100111| 0 |*******| 0 | 999| 15| 28 | |13+ | 11111|1110110111100000| 0 |*******| 0 | 999| 15| 29 | |14 | 11111|1110110111100000| 0 |*******| 0 | 1000| 16| 30 | |14+ | 11111|1110001100001000| 0 | -1| 1 | 1000| 16| 31 | |15 | 11111|1110001100001000| 0 | -1| 1 | 1000| 17| 32 | |15+ | 11111|0000000000010101| 0 |*******| 0 | 1000| 17| 33 | |16 | 11111|0000000000010101| 0 |*******| 0 | 21| 18| 34 | |16+ | 11111|1110011111000010| 0 |*******| 0 | 21| 18| 35 | |17 | 11111|1110011111000010| 0 |*******| 0 | 21| 21| 36 | |17+ | 11111|0000000000000010| 0 |*******| 0 | 21| 21| 37 | |18 | 11111|0000000000000010| 0 |*******| 0 | 2| 22| 38 | |18+ | 11111|1110000010010000| 0 |*******| 0 | 2| 22| 39 | |19 | 11111|1110000010010000| 0 |*******| 0 | 2| 23| 40 | |19+ | 11111|0000001111101000| 0 |*******| 0 | 2| 23| 41 | |20 | 11111|0000001111101000| 0 |*******| 0 | 1000| 24| 42 | |20+ | 11111|1110111010010000| 0 |*******| 0 | 1000| 24| 43 | |21 | 11111|1110111010010000| 0 |*******| 0 | 1000| 25| 44 | |21+ | 11111|1110001100000001| 0 |*******| 0 | 1000| 25| 45 | |22 | 11111|1110001100000001| 0 |*******| 0 | 1000| 26| 46 | |22+ | 11111|1110001100000010| 0 |*******| 0 | 1000| 26| 47 | |23 | 11111|1110001100000010| 0 |*******| 0 | 1000| 27| 48 | |23+ | 11111|1110001100000011| 0 |*******| 0 | 1000| 27| 49 | |24 | 11111|1110001100000011| 0 |*******| 0 | 1000| 28| 50 | |24+ | 11111|1110001100000100| 0 |*******| 0 | 1000| 28| 51 | |25 | 11111|1110001100000100| 0 |*******| 0 | 1000| 1000| 52 | |25+ | 11111|1110001100000101| 0 |*******| 0 | 1000| 1000| 53 | |26 | 11111|1110001100000101| 0 |*******| 0 | 1000| 1000| 54 | |26+ | 11111|1110001100000110| 0 |*******| 0 | 1000| 1000| 55 | |27 | 11111|1110001100000110| 0 |*******| 0 | 1000| 1000| 56 | |27+ | 11111|1110001100000111| 0 |*******| 0 | 1000| 1000| 57 | |28 | 11111|1110001100000111| 0 |*******| 0 | 1000| 1000| 58 | |28+ | 11111|1110101010010000| 0 |*******| 0 | 1000| 1000| 59 | |29 | 11111|1110101010010000| 0 |*******| 0 | 1000| 1001| 60 | |29+ | 11111|1110001100000001| 0 |*******| 0 | 1000| 1001| 61 | |30 | 11111|1110001100000001| 0 |*******| 0 | 1000| 1002| 62 | |30+ | 11111|1110001100000010| 0 |*******| 0 | 1000| 1002| 63 | |31 | 11111|1110001100000010| 0 |*******| 0 | 1000| 1000| 64 | |31+ | 11111|1110001100000011| 0 |*******| 0 | 1000| 1000| 65 | |32 | 11111|1110001100000011| 0 |*******| 0 | 1000| 1000| 66 | |32+ | 11111|1110001100000100| 0 |*******| 0 | 1000| 1000| 67 | |33 | 11111|1110001100000100| 0 |*******| 0 | 1000| 1001| 68 | |33+ | 11111|1110001100000101| 0 |*******| 0 | 1000| 1001| 69 | |34 | 11111|1110001100000101| 0 |*******| 0 | 1000| 1002| 70 | |34+ | 11111|1110001100000110| 0 |*******| 0 | 1000| 1002| 71 | |35 | 11111|1110001100000110| 0 |*******| 0 | 1000| 1000| 72 | |35+ | 11111|1110001100000111| 0 |*******| 0 | 1000| 1000| 73 | |36 | 11111|1110001100000111| 0 |*******| 0 | 1000| 1000| 74 | |36+ | 11111|1110111111010000| 0 |*******| 0 | 1000| 1000| 75 | |37 | 11111|1110111111010000| 0 |*******| 0 | 1000| 1001| 76 | |37+ | 11111|1110001100000001| 0 |*******| 0 | 1000| 1001| 77 | |38 | 11111|1110001100000001| 0 |*******| 0 | 1000| 1000| 78 | |38+ | 11111|1110001100000010| 0 |*******| 0 | 1000| 1000| 79 | |39 | 11111|1110001100000010| 0 |*******| 0 | 1000| 1001| 80 | |39+ | 11111|1110001100000011| 0 |*******| 0 | 1000| 1001| 81 | |40 | 11111|1110001100000011| 0 |*******| 0 | 1000| 1000| 82 | |40+ | 11111|1110001100000100| 0 |*******| 0 | 1000| 1000| 83 | |41 | 11111|1110001100000100| 0 |*******| 0 | 1000| 1001| 84 | |41+ | 11111|1110001100000101| 0 |*******| 0 | 1000| 1001| 85 | |42 | 11111|1110001100000101| 0 |*******| 0 | 1000| 1000| 86 | |42+ | 11111|1110001100000110| 0 |*******| 0 | 1000| 1000| 87 | |43 | 11111|1110001100000110| 0 |*******| 0 | 1000| 1001| 88 | |43+ | 11111|1110001100000111| 0 |*******| 0 | 1000| 1001| 89 | |44 | 11111|1110001100000111| 0 |*******| 0 | 1000| 1000| 90 | |44+ | 11111|1110001100000111| 1 |*******| 0 | 1000| 1000| 91 | |45 | 11111|1110001100000111| 1 |*******| 0 | 1000| 0| 92 | |45+ | 11111|0111111111111111| 0 |*******| 0 | 1000| 0| 93 | |46 | 11111|0111111111111111| 0 |*******| 0 |32767| 1| 94 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/Registers/Bit.out: -------------------------------------------------------------------------------- 1 | | time | in |load | out | 2 | | 0+ | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 0 | 4 | | 1+ | 0 | 1 | 0 | 5 | | 2 | 0 | 1 | 0 | 6 | | 2+ | 1 | 0 | 0 | 7 | | 3 | 1 | 0 | 0 | 8 | | 3+ | 1 | 1 | 0 | 9 | | 4 | 1 | 1 | 1 | 10 | | 4+ | 0 | 0 | 1 | 11 | | 5 | 0 | 0 | 1 | 12 | | 5+ | 1 | 0 | 1 | 13 | | 6 | 1 | 0 | 1 | 14 | | 6+ | 0 | 1 | 1 | 15 | | 7 | 0 | 1 | 0 | 16 | | 7+ | 1 | 1 | 0 | 17 | | 8 | 1 | 1 | 1 | 18 | | 8+ | 0 | 0 | 1 | 19 | | 9 | 0 | 0 | 1 | 20 | | 9+ | 0 | 0 | 1 | 21 | | 10 | 0 | 0 | 1 | 22 | | 10+ | 0 | 0 | 1 | 23 | | 11 | 0 | 0 | 1 | 24 | | 11+ | 0 | 0 | 1 | 25 | | 12 | 0 | 0 | 1 | 26 | | 12+ | 0 | 0 | 1 | 27 | | 13 | 0 | 0 | 1 | 28 | | 13+ | 0 | 0 | 1 | 29 | | 14 | 0 | 0 | 1 | 30 | | 14+ | 0 | 0 | 1 | 31 | | 15 | 0 | 0 | 1 | 32 | | 15+ | 0 | 0 | 1 | 33 | | 16 | 0 | 0 | 1 | 34 | | 16+ | 0 | 0 | 1 | 35 | | 17 | 0 | 0 | 1 | 36 | | 17+ | 0 | 0 | 1 | 37 | | 18 | 0 | 0 | 1 | 38 | | 18+ | 0 | 0 | 1 | 39 | | 19 | 0 | 0 | 1 | 40 | | 19+ | 0 | 0 | 1 | 41 | | 20 | 0 | 0 | 1 | 42 | | 20+ | 0 | 0 | 1 | 43 | | 21 | 0 | 0 | 1 | 44 | | 21+ | 0 | 0 | 1 | 45 | | 22 | 0 | 0 | 1 | 46 | | 22+ | 0 | 0 | 1 | 47 | | 23 | 0 | 0 | 1 | 48 | | 23+ | 0 | 0 | 1 | 49 | | 24 | 0 | 0 | 1 | 50 | | 24+ | 0 | 0 | 1 | 51 | | 25 | 0 | 0 | 1 | 52 | | 25+ | 0 | 0 | 1 | 53 | | 26 | 0 | 0 | 1 | 54 | | 26+ | 0 | 0 | 1 | 55 | | 27 | 0 | 0 | 1 | 56 | | 27+ | 0 | 0 | 1 | 57 | | 28 | 0 | 0 | 1 | 58 | | 28+ | 0 | 0 | 1 | 59 | | 29 | 0 | 0 | 1 | 60 | | 29+ | 0 | 0 | 1 | 61 | | 30 | 0 | 0 | 1 | 62 | | 30+ | 0 | 0 | 1 | 63 | | 31 | 0 | 0 | 1 | 64 | | 31+ | 0 | 0 | 1 | 65 | | 32 | 0 | 0 | 1 | 66 | | 32+ | 0 | 0 | 1 | 67 | | 33 | 0 | 0 | 1 | 68 | | 33+ | 0 | 0 | 1 | 69 | | 34 | 0 | 0 | 1 | 70 | | 34+ | 0 | 0 | 1 | 71 | | 35 | 0 | 0 | 1 | 72 | | 35+ | 0 | 0 | 1 | 73 | | 36 | 0 | 0 | 1 | 74 | | 36+ | 0 | 0 | 1 | 75 | | 37 | 0 | 0 | 1 | 76 | | 37+ | 0 | 0 | 1 | 77 | | 38 | 0 | 0 | 1 | 78 | | 38+ | 0 | 0 | 1 | 79 | | 39 | 0 | 0 | 1 | 80 | | 39+ | 0 | 0 | 1 | 81 | | 40 | 0 | 0 | 1 | 82 | | 40+ | 0 | 0 | 1 | 83 | | 41 | 0 | 0 | 1 | 84 | | 41+ | 0 | 0 | 1 | 85 | | 42 | 0 | 0 | 1 | 86 | | 42+ | 0 | 0 | 1 | 87 | | 43 | 0 | 0 | 1 | 88 | | 43+ | 0 | 0 | 1 | 89 | | 44 | 0 | 0 | 1 | 90 | | 44+ | 0 | 0 | 1 | 91 | | 45 | 0 | 0 | 1 | 92 | | 45+ | 0 | 0 | 1 | 93 | | 46 | 0 | 0 | 1 | 94 | | 46+ | 0 | 0 | 1 | 95 | | 47 | 0 | 0 | 1 | 96 | | 47+ | 0 | 0 | 1 | 97 | | 48 | 0 | 0 | 1 | 98 | | 48+ | 0 | 0 | 1 | 99 | | 49 | 0 | 0 | 1 | 100 | | 49+ | 0 | 0 | 1 | 101 | | 50 | 0 | 0 | 1 | 102 | | 50+ | 0 | 0 | 1 | 103 | | 51 | 0 | 0 | 1 | 104 | | 51+ | 0 | 0 | 1 | 105 | | 52 | 0 | 0 | 1 | 106 | | 52+ | 0 | 0 | 1 | 107 | | 53 | 0 | 0 | 1 | 108 | | 53+ | 0 | 0 | 1 | 109 | | 54 | 0 | 0 | 1 | 110 | | 54+ | 0 | 0 | 1 | 111 | | 55 | 0 | 0 | 1 | 112 | | 55+ | 0 | 0 | 1 | 113 | | 56 | 0 | 0 | 1 | 114 | | 56+ | 0 | 0 | 1 | 115 | | 57 | 0 | 0 | 1 | 116 | | 57+ | 0 | 1 | 1 | 117 | | 58 | 0 | 1 | 0 | 118 | | 58+ | 1 | 0 | 0 | 119 | | 59 | 1 | 0 | 0 | 120 | | 59+ | 1 | 0 | 0 | 121 | | 60 | 1 | 0 | 0 | 122 | | 60+ | 1 | 0 | 0 | 123 | | 61 | 1 | 0 | 0 | 124 | | 61+ | 1 | 0 | 0 | 125 | | 62 | 1 | 0 | 0 | 126 | | 62+ | 1 | 0 | 0 | 127 | | 63 | 1 | 0 | 0 | 128 | | 63+ | 1 | 0 | 0 | 129 | | 64 | 1 | 0 | 0 | 130 | | 64+ | 1 | 0 | 0 | 131 | | 65 | 1 | 0 | 0 | 132 | | 65+ | 1 | 0 | 0 | 133 | | 66 | 1 | 0 | 0 | 134 | | 66+ | 1 | 0 | 0 | 135 | | 67 | 1 | 0 | 0 | 136 | | 67+ | 1 | 0 | 0 | 137 | | 68 | 1 | 0 | 0 | 138 | | 68+ | 1 | 0 | 0 | 139 | | 69 | 1 | 0 | 0 | 140 | | 69+ | 1 | 0 | 0 | 141 | | 70 | 1 | 0 | 0 | 142 | | 70+ | 1 | 0 | 0 | 143 | | 71 | 1 | 0 | 0 | 144 | | 71+ | 1 | 0 | 0 | 145 | | 72 | 1 | 0 | 0 | 146 | | 72+ | 1 | 0 | 0 | 147 | | 73 | 1 | 0 | 0 | 148 | | 73+ | 1 | 0 | 0 | 149 | | 74 | 1 | 0 | 0 | 150 | | 74+ | 1 | 0 | 0 | 151 | | 75 | 1 | 0 | 0 | 152 | | 75+ | 1 | 0 | 0 | 153 | | 76 | 1 | 0 | 0 | 154 | | 76+ | 1 | 0 | 0 | 155 | | 77 | 1 | 0 | 0 | 156 | | 77+ | 1 | 0 | 0 | 157 | | 78 | 1 | 0 | 0 | 158 | | 78+ | 1 | 0 | 0 | 159 | | 79 | 1 | 0 | 0 | 160 | | 79+ | 1 | 0 | 0 | 161 | | 80 | 1 | 0 | 0 | 162 | | 80+ | 1 | 0 | 0 | 163 | | 81 | 1 | 0 | 0 | 164 | | 81+ | 1 | 0 | 0 | 165 | | 82 | 1 | 0 | 0 | 166 | | 82+ | 1 | 0 | 0 | 167 | | 83 | 1 | 0 | 0 | 168 | | 83+ | 1 | 0 | 0 | 169 | | 84 | 1 | 0 | 0 | 170 | | 84+ | 1 | 0 | 0 | 171 | | 85 | 1 | 0 | 0 | 172 | | 85+ | 1 | 0 | 0 | 173 | | 86 | 1 | 0 | 0 | 174 | | 86+ | 1 | 0 | 0 | 175 | | 87 | 1 | 0 | 0 | 176 | | 87+ | 1 | 0 | 0 | 177 | | 88 | 1 | 0 | 0 | 178 | | 88+ | 1 | 0 | 0 | 179 | | 89 | 1 | 0 | 0 | 180 | | 89+ | 1 | 0 | 0 | 181 | | 90 | 1 | 0 | 0 | 182 | | 90+ | 1 | 0 | 0 | 183 | | 91 | 1 | 0 | 0 | 184 | | 91+ | 1 | 0 | 0 | 185 | | 92 | 1 | 0 | 0 | 186 | | 92+ | 1 | 0 | 0 | 187 | | 93 | 1 | 0 | 0 | 188 | | 93+ | 1 | 0 | 0 | 189 | | 94 | 1 | 0 | 0 | 190 | | 94+ | 1 | 0 | 0 | 191 | | 95 | 1 | 0 | 0 | 192 | | 95+ | 1 | 0 | 0 | 193 | | 96 | 1 | 0 | 0 | 194 | | 96+ | 1 | 0 | 0 | 195 | | 97 | 1 | 0 | 0 | 196 | | 97+ | 1 | 0 | 0 | 197 | | 98 | 1 | 0 | 0 | 198 | | 98+ | 1 | 0 | 0 | 199 | | 99 | 1 | 0 | 0 | 200 | | 99+ | 1 | 0 | 0 | 201 | | 100 | 1 | 0 | 0 | 202 | | 100+ | 1 | 0 | 0 | 203 | | 101 | 1 | 0 | 0 | 204 | | 101+ | 1 | 0 | 0 | 205 | | 102 | 1 | 0 | 0 | 206 | | 102+ | 1 | 0 | 0 | 207 | | 103 | 1 | 0 | 0 | 208 | | 103+ | 1 | 0 | 0 | 209 | | 104 | 1 | 0 | 0 | 210 | | 104+ | 1 | 0 | 0 | 211 | | 105 | 1 | 0 | 0 | 212 | | 105+ | 1 | 0 | 0 | 213 | | 106 | 1 | 0 | 0 | 214 | | 106+ | 1 | 0 | 0 | 215 | | 107 | 1 | 0 | 0 | 216 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/3. Memory units and PC (sequential chips)/Registers/Bit.cmp: -------------------------------------------------------------------------------- 1 | | time | in |load | out | 2 | | 0+ | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 0 | 4 | | 1+ | 0 | 1 | 0 | 5 | | 2 | 0 | 1 | 0 | 6 | | 2+ | 1 | 0 | 0 | 7 | | 3 | 1 | 0 | 0 | 8 | | 3+ | 1 | 1 | 0 | 9 | | 4 | 1 | 1 | 1 | 10 | | 4+ | 0 | 0 | 1 | 11 | | 5 | 0 | 0 | 1 | 12 | | 5+ | 1 | 0 | 1 | 13 | | 6 | 1 | 0 | 1 | 14 | | 6+ | 0 | 1 | 1 | 15 | | 7 | 0 | 1 | 0 | 16 | | 7+ | 1 | 1 | 0 | 17 | | 8 | 1 | 1 | 1 | 18 | | 8+ | 0 | 0 | 1 | 19 | | 9 | 0 | 0 | 1 | 20 | | 9+ | 0 | 0 | 1 | 21 | | 10 | 0 | 0 | 1 | 22 | | 10+ | 0 | 0 | 1 | 23 | | 11 | 0 | 0 | 1 | 24 | | 11+ | 0 | 0 | 1 | 25 | | 12 | 0 | 0 | 1 | 26 | | 12+ | 0 | 0 | 1 | 27 | | 13 | 0 | 0 | 1 | 28 | | 13+ | 0 | 0 | 1 | 29 | | 14 | 0 | 0 | 1 | 30 | | 14+ | 0 | 0 | 1 | 31 | | 15 | 0 | 0 | 1 | 32 | | 15+ | 0 | 0 | 1 | 33 | | 16 | 0 | 0 | 1 | 34 | | 16+ | 0 | 0 | 1 | 35 | | 17 | 0 | 0 | 1 | 36 | | 17+ | 0 | 0 | 1 | 37 | | 18 | 0 | 0 | 1 | 38 | | 18+ | 0 | 0 | 1 | 39 | | 19 | 0 | 0 | 1 | 40 | | 19+ | 0 | 0 | 1 | 41 | | 20 | 0 | 0 | 1 | 42 | | 20+ | 0 | 0 | 1 | 43 | | 21 | 0 | 0 | 1 | 44 | | 21+ | 0 | 0 | 1 | 45 | | 22 | 0 | 0 | 1 | 46 | | 22+ | 0 | 0 | 1 | 47 | | 23 | 0 | 0 | 1 | 48 | | 23+ | 0 | 0 | 1 | 49 | | 24 | 0 | 0 | 1 | 50 | | 24+ | 0 | 0 | 1 | 51 | | 25 | 0 | 0 | 1 | 52 | | 25+ | 0 | 0 | 1 | 53 | | 26 | 0 | 0 | 1 | 54 | | 26+ | 0 | 0 | 1 | 55 | | 27 | 0 | 0 | 1 | 56 | | 27+ | 0 | 0 | 1 | 57 | | 28 | 0 | 0 | 1 | 58 | | 28+ | 0 | 0 | 1 | 59 | | 29 | 0 | 0 | 1 | 60 | | 29+ | 0 | 0 | 1 | 61 | | 30 | 0 | 0 | 1 | 62 | | 30+ | 0 | 0 | 1 | 63 | | 31 | 0 | 0 | 1 | 64 | | 31+ | 0 | 0 | 1 | 65 | | 32 | 0 | 0 | 1 | 66 | | 32+ | 0 | 0 | 1 | 67 | | 33 | 0 | 0 | 1 | 68 | | 33+ | 0 | 0 | 1 | 69 | | 34 | 0 | 0 | 1 | 70 | | 34+ | 0 | 0 | 1 | 71 | | 35 | 0 | 0 | 1 | 72 | | 35+ | 0 | 0 | 1 | 73 | | 36 | 0 | 0 | 1 | 74 | | 36+ | 0 | 0 | 1 | 75 | | 37 | 0 | 0 | 1 | 76 | | 37+ | 0 | 0 | 1 | 77 | | 38 | 0 | 0 | 1 | 78 | | 38+ | 0 | 0 | 1 | 79 | | 39 | 0 | 0 | 1 | 80 | | 39+ | 0 | 0 | 1 | 81 | | 40 | 0 | 0 | 1 | 82 | | 40+ | 0 | 0 | 1 | 83 | | 41 | 0 | 0 | 1 | 84 | | 41+ | 0 | 0 | 1 | 85 | | 42 | 0 | 0 | 1 | 86 | | 42+ | 0 | 0 | 1 | 87 | | 43 | 0 | 0 | 1 | 88 | | 43+ | 0 | 0 | 1 | 89 | | 44 | 0 | 0 | 1 | 90 | | 44+ | 0 | 0 | 1 | 91 | | 45 | 0 | 0 | 1 | 92 | | 45+ | 0 | 0 | 1 | 93 | | 46 | 0 | 0 | 1 | 94 | | 46+ | 0 | 0 | 1 | 95 | | 47 | 0 | 0 | 1 | 96 | | 47+ | 0 | 0 | 1 | 97 | | 48 | 0 | 0 | 1 | 98 | | 48+ | 0 | 0 | 1 | 99 | | 49 | 0 | 0 | 1 | 100 | | 49+ | 0 | 0 | 1 | 101 | | 50 | 0 | 0 | 1 | 102 | | 50+ | 0 | 0 | 1 | 103 | | 51 | 0 | 0 | 1 | 104 | | 51+ | 0 | 0 | 1 | 105 | | 52 | 0 | 0 | 1 | 106 | | 52+ | 0 | 0 | 1 | 107 | | 53 | 0 | 0 | 1 | 108 | | 53+ | 0 | 0 | 1 | 109 | | 54 | 0 | 0 | 1 | 110 | | 54+ | 0 | 0 | 1 | 111 | | 55 | 0 | 0 | 1 | 112 | | 55+ | 0 | 0 | 1 | 113 | | 56 | 0 | 0 | 1 | 114 | | 56+ | 0 | 0 | 1 | 115 | | 57 | 0 | 0 | 1 | 116 | | 57+ | 0 | 1 | 1 | 117 | | 58 | 0 | 1 | 0 | 118 | | 58+ | 1 | 0 | 0 | 119 | | 59 | 1 | 0 | 0 | 120 | | 59+ | 1 | 0 | 0 | 121 | | 60 | 1 | 0 | 0 | 122 | | 60+ | 1 | 0 | 0 | 123 | | 61 | 1 | 0 | 0 | 124 | | 61+ | 1 | 0 | 0 | 125 | | 62 | 1 | 0 | 0 | 126 | | 62+ | 1 | 0 | 0 | 127 | | 63 | 1 | 0 | 0 | 128 | | 63+ | 1 | 0 | 0 | 129 | | 64 | 1 | 0 | 0 | 130 | | 64+ | 1 | 0 | 0 | 131 | | 65 | 1 | 0 | 0 | 132 | | 65+ | 1 | 0 | 0 | 133 | | 66 | 1 | 0 | 0 | 134 | | 66+ | 1 | 0 | 0 | 135 | | 67 | 1 | 0 | 0 | 136 | | 67+ | 1 | 0 | 0 | 137 | | 68 | 1 | 0 | 0 | 138 | | 68+ | 1 | 0 | 0 | 139 | | 69 | 1 | 0 | 0 | 140 | | 69+ | 1 | 0 | 0 | 141 | | 70 | 1 | 0 | 0 | 142 | | 70+ | 1 | 0 | 0 | 143 | | 71 | 1 | 0 | 0 | 144 | | 71+ | 1 | 0 | 0 | 145 | | 72 | 1 | 0 | 0 | 146 | | 72+ | 1 | 0 | 0 | 147 | | 73 | 1 | 0 | 0 | 148 | | 73+ | 1 | 0 | 0 | 149 | | 74 | 1 | 0 | 0 | 150 | | 74+ | 1 | 0 | 0 | 151 | | 75 | 1 | 0 | 0 | 152 | | 75+ | 1 | 0 | 0 | 153 | | 76 | 1 | 0 | 0 | 154 | | 76+ | 1 | 0 | 0 | 155 | | 77 | 1 | 0 | 0 | 156 | | 77+ | 1 | 0 | 0 | 157 | | 78 | 1 | 0 | 0 | 158 | | 78+ | 1 | 0 | 0 | 159 | | 79 | 1 | 0 | 0 | 160 | | 79+ | 1 | 0 | 0 | 161 | | 80 | 1 | 0 | 0 | 162 | | 80+ | 1 | 0 | 0 | 163 | | 81 | 1 | 0 | 0 | 164 | | 81+ | 1 | 0 | 0 | 165 | | 82 | 1 | 0 | 0 | 166 | | 82+ | 1 | 0 | 0 | 167 | | 83 | 1 | 0 | 0 | 168 | | 83+ | 1 | 0 | 0 | 169 | | 84 | 1 | 0 | 0 | 170 | | 84+ | 1 | 0 | 0 | 171 | | 85 | 1 | 0 | 0 | 172 | | 85+ | 1 | 0 | 0 | 173 | | 86 | 1 | 0 | 0 | 174 | | 86+ | 1 | 0 | 0 | 175 | | 87 | 1 | 0 | 0 | 176 | | 87+ | 1 | 0 | 0 | 177 | | 88 | 1 | 0 | 0 | 178 | | 88+ | 1 | 0 | 0 | 179 | | 89 | 1 | 0 | 0 | 180 | | 89+ | 1 | 0 | 0 | 181 | | 90 | 1 | 0 | 0 | 182 | | 90+ | 1 | 0 | 0 | 183 | | 91 | 1 | 0 | 0 | 184 | | 91+ | 1 | 0 | 0 | 185 | | 92 | 1 | 0 | 0 | 186 | | 92+ | 1 | 0 | 0 | 187 | | 93 | 1 | 0 | 0 | 188 | | 93+ | 1 | 0 | 0 | 189 | | 94 | 1 | 0 | 0 | 190 | | 94+ | 1 | 0 | 0 | 191 | | 95 | 1 | 0 | 0 | 192 | | 95+ | 1 | 0 | 0 | 193 | | 96 | 1 | 0 | 0 | 194 | | 96+ | 1 | 0 | 0 | 195 | | 97 | 1 | 0 | 0 | 196 | | 97+ | 1 | 0 | 0 | 197 | | 98 | 1 | 0 | 0 | 198 | | 98+ | 1 | 0 | 0 | 199 | | 99 | 1 | 0 | 0 | 200 | | 99+ | 1 | 0 | 0 | 201 | | 100 | 1 | 0 | 0 | 202 | | 100+ | 1 | 0 | 0 | 203 | | 101 | 1 | 0 | 0 | 204 | | 101+ | 1 | 0 | 0 | 205 | | 102 | 1 | 0 | 0 | 206 | | 102+ | 1 | 0 | 0 | 207 | | 103 | 1 | 0 | 0 | 208 | | 103+ | 1 | 0 | 0 | 209 | | 104 | 1 | 0 | 0 | 210 | | 104+ | 1 | 0 | 0 | 211 | | 105 | 1 | 0 | 0 | 212 | | 105+ | 1 | 0 | 0 | 213 | | 106 | 1 | 0 | 0 | 214 | | 106+ | 1 | 0 | 0 | 215 | | 107 | 1 | 0 | 0 | 216 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/CPU/CPU.out: -------------------------------------------------------------------------------- 1 | |time| inM | instruction |reset| outM |writeM |addre| pc |DRegiste| 2 | |0+ | 0|0011000000111001| 0 | 0| 0 | 0| 0| 0 | 3 | |1 | 0|0011000000111001| 0 | 0| 0 |12345| 1| 0 | 4 | |1+ | 0|1110110000010000| 0 | 12345| 0 |12345| 1| 12345 | 5 | |2 | 0|1110110000010000| 0 | 12345| 0 |12345| 2| 12345 | 6 | |2+ | 0|0101101110100000| 0 | -1| 0 |12345| 2| 12345 | 7 | |3 | 0|0101101110100000| 0 | -1| 0 |23456| 3| 12345 | 8 | |3+ | 0|1110000111010000| 0 | 11111| 0 |23456| 3| 11111 | 9 | |4 | 0|1110000111010000| 0 | 12345| 0 |23456| 4| 11111 | 10 | |4+ | 0|0000001111101000| 0 | -11111| 0 |23456| 4| 11111 | 11 | |5 | 0|0000001111101000| 0 | -11111| 0 | 1000| 5| 11111 | 12 | |5+ | 0|1110001100001000| 0 | 11111| 1 | 1000| 5| 11111 | 13 | |6 | 0|1110001100001000| 0 | 11111| 1 | 1000| 6| 11111 | 14 | |6+ | 0|0000001111101001| 0 | -11111| 0 | 1000| 6| 11111 | 15 | |7 | 0|0000001111101001| 0 | -11111| 0 | 1001| 7| 11111 | 16 | |7+ | 0|1110001110011000| 0 | 11110| 1 | 1001| 7| 11110 | 17 | |8 | 0|1110001110011000| 0 | 11109| 1 | 1001| 8| 11110 | 18 | |8+ | 0|0000001111101000| 0 | -11110| 0 | 1001| 8| 11110 | 19 | |9 | 0|0000001111101000| 0 | -11110| 0 | 1000| 9| 11110 | 20 | |9+ | 11111|1111010011010000| 0 | -1| 0 | 1000| 9| -1 | 21 | |10 | 11111|1111010011010000| 0 | -11112| 0 | 1000| 10| -1 | 22 | |10+ | 11111|0000000000001110| 0 | 1000| 0 | 1000| 10| -1 | 23 | |11 | 11111|0000000000001110| 0 | 14| 0 | 14| 11| -1 | 24 | |11+ | 11111|1110001100000100| 0 | -1| 0 | 14| 11| -1 | 25 | |12 | 11111|1110001100000100| 0 | -1| 0 | 14| 14| -1 | 26 | |12+ | 11111|0000001111100111| 0 | 1| 0 | 14| 14| -1 | 27 | |13 | 11111|0000001111100111| 0 | 1| 0 | 999| 15| -1 | 28 | |13+ | 11111|1110110111100000| 0 | 1000| 0 | 999| 15| -1 | 29 | |14 | 11111|1110110111100000| 0 | 1001| 0 | 1000| 16| -1 | 30 | |14+ | 11111|1110001100001000| 0 | -1| 1 | 1000| 16| -1 | 31 | |15 | 11111|1110001100001000| 0 | -1| 1 | 1000| 17| -1 | 32 | |15+ | 11111|0000000000010101| 0 | 1000| 0 | 1000| 17| -1 | 33 | |16 | 11111|0000000000010101| 0 | 21| 0 | 21| 18| -1 | 34 | |16+ | 11111|1110011111000010| 0 | 0| 0 | 21| 18| -1 | 35 | |17 | 11111|1110011111000010| 0 | 0| 0 | 21| 21| -1 | 36 | |17+ | 11111|0000000000000010| 0 | 21| 0 | 21| 21| -1 | 37 | |18 | 11111|0000000000000010| 0 | 2| 0 | 2| 22| -1 | 38 | |18+ | 11111|1110000010010000| 0 | 1| 0 | 2| 22| 1 | 39 | |19 | 11111|1110000010010000| 0 | 3| 0 | 2| 23| 1 | 40 | |19+ | 11111|0000001111101000| 0 | -1| 0 | 2| 23| 1 | 41 | |20 | 11111|0000001111101000| 0 | -1| 0 | 1000| 24| 1 | 42 | |20+ | 11111|1110111010010000| 0 | -1| 0 | 1000| 24| -1 | 43 | |21 | 11111|1110111010010000| 0 | -1| 0 | 1000| 25| -1 | 44 | |21+ | 11111|1110001100000001| 0 | -1| 0 | 1000| 25| -1 | 45 | |22 | 11111|1110001100000001| 0 | -1| 0 | 1000| 26| -1 | 46 | |22+ | 11111|1110001100000010| 0 | -1| 0 | 1000| 26| -1 | 47 | |23 | 11111|1110001100000010| 0 | -1| 0 | 1000| 27| -1 | 48 | |23+ | 11111|1110001100000011| 0 | -1| 0 | 1000| 27| -1 | 49 | |24 | 11111|1110001100000011| 0 | -1| 0 | 1000| 28| -1 | 50 | |24+ | 11111|1110001100000100| 0 | -1| 0 | 1000| 28| -1 | 51 | |25 | 11111|1110001100000100| 0 | -1| 0 | 1000| 1000| -1 | 52 | |25+ | 11111|1110001100000101| 0 | -1| 0 | 1000| 1000| -1 | 53 | |26 | 11111|1110001100000101| 0 | -1| 0 | 1000| 1000| -1 | 54 | |26+ | 11111|1110001100000110| 0 | -1| 0 | 1000| 1000| -1 | 55 | |27 | 11111|1110001100000110| 0 | -1| 0 | 1000| 1000| -1 | 56 | |27+ | 11111|1110001100000111| 0 | -1| 0 | 1000| 1000| -1 | 57 | |28 | 11111|1110001100000111| 0 | -1| 0 | 1000| 1000| -1 | 58 | |28+ | 11111|1110101010010000| 0 | 0| 0 | 1000| 1000| 0 | 59 | |29 | 11111|1110101010010000| 0 | 0| 0 | 1000| 1001| 0 | 60 | |29+ | 11111|1110001100000001| 0 | 0| 0 | 1000| 1001| 0 | 61 | |30 | 11111|1110001100000001| 0 | 0| 0 | 1000| 1002| 0 | 62 | |30+ | 11111|1110001100000010| 0 | 0| 0 | 1000| 1002| 0 | 63 | |31 | 11111|1110001100000010| 0 | 0| 0 | 1000| 1000| 0 | 64 | |31+ | 11111|1110001100000011| 0 | 0| 0 | 1000| 1000| 0 | 65 | |32 | 11111|1110001100000011| 0 | 0| 0 | 1000| 1000| 0 | 66 | |32+ | 11111|1110001100000100| 0 | 0| 0 | 1000| 1000| 0 | 67 | |33 | 11111|1110001100000100| 0 | 0| 0 | 1000| 1001| 0 | 68 | |33+ | 11111|1110001100000101| 0 | 0| 0 | 1000| 1001| 0 | 69 | |34 | 11111|1110001100000101| 0 | 0| 0 | 1000| 1002| 0 | 70 | |34+ | 11111|1110001100000110| 0 | 0| 0 | 1000| 1002| 0 | 71 | |35 | 11111|1110001100000110| 0 | 0| 0 | 1000| 1000| 0 | 72 | |35+ | 11111|1110001100000111| 0 | 0| 0 | 1000| 1000| 0 | 73 | |36 | 11111|1110001100000111| 0 | 0| 0 | 1000| 1000| 0 | 74 | |36+ | 11111|1110111111010000| 0 | 1| 0 | 1000| 1000| 1 | 75 | |37 | 11111|1110111111010000| 0 | 1| 0 | 1000| 1001| 1 | 76 | |37+ | 11111|1110001100000001| 0 | 1| 0 | 1000| 1001| 1 | 77 | |38 | 11111|1110001100000001| 0 | 1| 0 | 1000| 1000| 1 | 78 | |38+ | 11111|1110001100000010| 0 | 1| 0 | 1000| 1000| 1 | 79 | |39 | 11111|1110001100000010| 0 | 1| 0 | 1000| 1001| 1 | 80 | |39+ | 11111|1110001100000011| 0 | 1| 0 | 1000| 1001| 1 | 81 | |40 | 11111|1110001100000011| 0 | 1| 0 | 1000| 1000| 1 | 82 | |40+ | 11111|1110001100000100| 0 | 1| 0 | 1000| 1000| 1 | 83 | |41 | 11111|1110001100000100| 0 | 1| 0 | 1000| 1001| 1 | 84 | |41+ | 11111|1110001100000101| 0 | 1| 0 | 1000| 1001| 1 | 85 | |42 | 11111|1110001100000101| 0 | 1| 0 | 1000| 1000| 1 | 86 | |42+ | 11111|1110001100000110| 0 | 1| 0 | 1000| 1000| 1 | 87 | |43 | 11111|1110001100000110| 0 | 1| 0 | 1000| 1001| 1 | 88 | |43+ | 11111|1110001100000111| 0 | 1| 0 | 1000| 1001| 1 | 89 | |44 | 11111|1110001100000111| 0 | 1| 0 | 1000| 1000| 1 | 90 | |44+ | 11111|1110001100000111| 1 | 1| 0 | 1000| 1000| 1 | 91 | |45 | 11111|1110001100000111| 1 | 1| 0 | 1000| 0| 1 | 92 | |45+ | 11111|0111111111111111| 0 | 1| 0 | 1000| 0| 1 | 93 | |46 | 11111|0111111111111111| 0 | 1| 0 |32767| 1| 1 | 94 | -------------------------------------------------------------------------------- /Hack-Computer-description-in-HDL/5. Hack Computer/CPU/CPU.cmp: -------------------------------------------------------------------------------- 1 | |time| inM | instruction |reset| outM |writeM |addre| pc |DRegiste| 2 | |0+ | 0|0011000000111001| 0 |*******| 0 | 0| 0| 0 | 3 | |1 | 0|0011000000111001| 0 |*******| 0 |12345| 1| 0 | 4 | |1+ | 0|1110110000010000| 0 |*******| 0 |12345| 1| 12345 | 5 | |2 | 0|1110110000010000| 0 |*******| 0 |12345| 2| 12345 | 6 | |2+ | 0|0101101110100000| 0 |*******| 0 |12345| 2| 12345 | 7 | |3 | 0|0101101110100000| 0 |*******| 0 |23456| 3| 12345 | 8 | |3+ | 0|1110000111010000| 0 |*******| 0 |23456| 3| 11111 | 9 | |4 | 0|1110000111010000| 0 |*******| 0 |23456| 4| 11111 | 10 | |4+ | 0|0000001111101000| 0 |*******| 0 |23456| 4| 11111 | 11 | |5 | 0|0000001111101000| 0 |*******| 0 | 1000| 5| 11111 | 12 | |5+ | 0|1110001100001000| 0 | 11111| 1 | 1000| 5| 11111 | 13 | |6 | 0|1110001100001000| 0 | 11111| 1 | 1000| 6| 11111 | 14 | |6+ | 0|0000001111101001| 0 |*******| 0 | 1000| 6| 11111 | 15 | |7 | 0|0000001111101001| 0 |*******| 0 | 1001| 7| 11111 | 16 | |7+ | 0|1110001110011000| 0 | 11110| 1 | 1001| 7| 11110 | 17 | |8 | 0|1110001110011000| 0 | 11109| 1 | 1001| 8| 11110 | 18 | |8+ | 0|0000001111101000| 0 |*******| 0 | 1001| 8| 11110 | 19 | |9 | 0|0000001111101000| 0 |*******| 0 | 1000| 9| 11110 | 20 | |9+ | 11111|1111010011010000| 0 |*******| 0 | 1000| 9| -1 | 21 | |10 | 11111|1111010011010000| 0 |*******| 0 | 1000| 10| -1 | 22 | |10+ | 11111|0000000000001110| 0 |*******| 0 | 1000| 10| -1 | 23 | |11 | 11111|0000000000001110| 0 |*******| 0 | 14| 11| -1 | 24 | |11+ | 11111|1110001100000100| 0 |*******| 0 | 14| 11| -1 | 25 | |12 | 11111|1110001100000100| 0 |*******| 0 | 14| 14| -1 | 26 | |12+ | 11111|0000001111100111| 0 |*******| 0 | 14| 14| -1 | 27 | |13 | 11111|0000001111100111| 0 |*******| 0 | 999| 15| -1 | 28 | |13+ | 11111|1110110111100000| 0 |*******| 0 | 999| 15| -1 | 29 | |14 | 11111|1110110111100000| 0 |*******| 0 | 1000| 16| -1 | 30 | |14+ | 11111|1110001100001000| 0 | -1| 1 | 1000| 16| -1 | 31 | |15 | 11111|1110001100001000| 0 | -1| 1 | 1000| 17| -1 | 32 | |15+ | 11111|0000000000010101| 0 |*******| 0 | 1000| 17| -1 | 33 | |16 | 11111|0000000000010101| 0 |*******| 0 | 21| 18| -1 | 34 | |16+ | 11111|1110011111000010| 0 |*******| 0 | 21| 18| -1 | 35 | |17 | 11111|1110011111000010| 0 |*******| 0 | 21| 21| -1 | 36 | |17+ | 11111|0000000000000010| 0 |*******| 0 | 21| 21| -1 | 37 | |18 | 11111|0000000000000010| 0 |*******| 0 | 2| 22| -1 | 38 | |18+ | 11111|1110000010010000| 0 |*******| 0 | 2| 22| 1 | 39 | |19 | 11111|1110000010010000| 0 |*******| 0 | 2| 23| 1 | 40 | |19+ | 11111|0000001111101000| 0 |*******| 0 | 2| 23| 1 | 41 | |20 | 11111|0000001111101000| 0 |*******| 0 | 1000| 24| 1 | 42 | |20+ | 11111|1110111010010000| 0 |*******| 0 | 1000| 24| -1 | 43 | |21 | 11111|1110111010010000| 0 |*******| 0 | 1000| 25| -1 | 44 | |21+ | 11111|1110001100000001| 0 |*******| 0 | 1000| 25| -1 | 45 | |22 | 11111|1110001100000001| 0 |*******| 0 | 1000| 26| -1 | 46 | |22+ | 11111|1110001100000010| 0 |*******| 0 | 1000| 26| -1 | 47 | |23 | 11111|1110001100000010| 0 |*******| 0 | 1000| 27| -1 | 48 | |23+ | 11111|1110001100000011| 0 |*******| 0 | 1000| 27| -1 | 49 | |24 | 11111|1110001100000011| 0 |*******| 0 | 1000| 28| -1 | 50 | |24+ | 11111|1110001100000100| 0 |*******| 0 | 1000| 28| -1 | 51 | |25 | 11111|1110001100000100| 0 |*******| 0 | 1000| 1000| -1 | 52 | |25+ | 11111|1110001100000101| 0 |*******| 0 | 1000| 1000| -1 | 53 | |26 | 11111|1110001100000101| 0 |*******| 0 | 1000| 1000| -1 | 54 | |26+ | 11111|1110001100000110| 0 |*******| 0 | 1000| 1000| -1 | 55 | |27 | 11111|1110001100000110| 0 |*******| 0 | 1000| 1000| -1 | 56 | |27+ | 11111|1110001100000111| 0 |*******| 0 | 1000| 1000| -1 | 57 | |28 | 11111|1110001100000111| 0 |*******| 0 | 1000| 1000| -1 | 58 | |28+ | 11111|1110101010010000| 0 |*******| 0 | 1000| 1000| 0 | 59 | |29 | 11111|1110101010010000| 0 |*******| 0 | 1000| 1001| 0 | 60 | |29+ | 11111|1110001100000001| 0 |*******| 0 | 1000| 1001| 0 | 61 | |30 | 11111|1110001100000001| 0 |*******| 0 | 1000| 1002| 0 | 62 | |30+ | 11111|1110001100000010| 0 |*******| 0 | 1000| 1002| 0 | 63 | |31 | 11111|1110001100000010| 0 |*******| 0 | 1000| 1000| 0 | 64 | |31+ | 11111|1110001100000011| 0 |*******| 0 | 1000| 1000| 0 | 65 | |32 | 11111|1110001100000011| 0 |*******| 0 | 1000| 1000| 0 | 66 | |32+ | 11111|1110001100000100| 0 |*******| 0 | 1000| 1000| 0 | 67 | |33 | 11111|1110001100000100| 0 |*******| 0 | 1000| 1001| 0 | 68 | |33+ | 11111|1110001100000101| 0 |*******| 0 | 1000| 1001| 0 | 69 | |34 | 11111|1110001100000101| 0 |*******| 0 | 1000| 1002| 0 | 70 | |34+ | 11111|1110001100000110| 0 |*******| 0 | 1000| 1002| 0 | 71 | |35 | 11111|1110001100000110| 0 |*******| 0 | 1000| 1000| 0 | 72 | |35+ | 11111|1110001100000111| 0 |*******| 0 | 1000| 1000| 0 | 73 | |36 | 11111|1110001100000111| 0 |*******| 0 | 1000| 1000| 0 | 74 | |36+ | 11111|1110111111010000| 0 |*******| 0 | 1000| 1000| 1 | 75 | |37 | 11111|1110111111010000| 0 |*******| 0 | 1000| 1001| 1 | 76 | |37+ | 11111|1110001100000001| 0 |*******| 0 | 1000| 1001| 1 | 77 | |38 | 11111|1110001100000001| 0 |*******| 0 | 1000| 1000| 1 | 78 | |38+ | 11111|1110001100000010| 0 |*******| 0 | 1000| 1000| 1 | 79 | |39 | 11111|1110001100000010| 0 |*******| 0 | 1000| 1001| 1 | 80 | |39+ | 11111|1110001100000011| 0 |*******| 0 | 1000| 1001| 1 | 81 | |40 | 11111|1110001100000011| 0 |*******| 0 | 1000| 1000| 1 | 82 | |40+ | 11111|1110001100000100| 0 |*******| 0 | 1000| 1000| 1 | 83 | |41 | 11111|1110001100000100| 0 |*******| 0 | 1000| 1001| 1 | 84 | |41+ | 11111|1110001100000101| 0 |*******| 0 | 1000| 1001| 1 | 85 | |42 | 11111|1110001100000101| 0 |*******| 0 | 1000| 1000| 1 | 86 | |42+ | 11111|1110001100000110| 0 |*******| 0 | 1000| 1000| 1 | 87 | |43 | 11111|1110001100000110| 0 |*******| 0 | 1000| 1001| 1 | 88 | |43+ | 11111|1110001100000111| 0 |*******| 0 | 1000| 1001| 1 | 89 | |44 | 11111|1110001100000111| 0 |*******| 0 | 1000| 1000| 1 | 90 | |44+ | 11111|1110001100000111| 1 |*******| 0 | 1000| 1000| 1 | 91 | |45 | 11111|1110001100000111| 1 |*******| 0 | 1000| 0| 1 | 92 | |45+ | 11111|0111111111111111| 0 |*******| 0 | 1000| 0| 1 | 93 | |46 | 11111|0111111111111111| 0 |*******| 0 |32767| 1| 1 | 94 | --------------------------------------------------------------------------------