├── .gitignore ├── README.md ├── project01 ├── And.cmp ├── And.hdl ├── And.tst ├── And16.cmp ├── And16.hdl ├── And16.tst ├── DMux.cmp ├── DMux.hdl ├── DMux.tst ├── DMux4Way.cmp ├── DMux4Way.hdl ├── DMux4Way.tst ├── DMux8Way.cmp ├── DMux8Way.hdl ├── DMux8Way.tst ├── Mux.cmp ├── Mux.hdl ├── Mux.tst ├── Mux16.cmp ├── Mux16.hdl ├── Mux16.tst ├── Mux4Way16.cmp ├── Mux4Way16.hdl ├── Mux4Way16.tst ├── Mux8Way16.cmp ├── Mux8Way16.hdl ├── Mux8Way16.tst ├── Not.cmp ├── Not.hdl ├── Not.tst ├── Not16.cmp ├── Not16.hdl ├── Not16.tst ├── Or.cmp ├── Or.hdl ├── Or.tst ├── Or16.cmp ├── Or16.hdl ├── Or16.tst ├── Or8Way.cmp ├── Or8Way.hdl ├── Or8Way.tst ├── Xor.cmp ├── Xor.hdl └── Xor.tst ├── project02.5 ├── ClkRSLatch.hdl ├── ClkRSLatch.tst ├── DFFn.hdl ├── DFFn.tst ├── RSFF.hdl ├── RSFF.tst ├── RSLatch.hdl ├── RSLatch.tst ├── SNand.hdl └── SNot.hdl ├── project02 ├── ALU.cmp ├── ALU.hdl ├── ALU.tst ├── Add16.cmp ├── Add16.hdl ├── Add16.tst ├── FullAdder.cmp ├── FullAdder.hdl ├── FullAdder.tst ├── HalfAdder.cmp ├── HalfAdder.hdl ├── HalfAdder.tst ├── Inc16.cmp ├── Inc16.hdl ├── Inc16.tst ├── IsNeg.hdl └── Or16Way.hdl ├── project03 ├── a │ ├── Bit.cmp │ ├── Bit.hdl │ ├── Bit.tst │ ├── PC.cmp │ ├── PC.hdl │ ├── PC.tst │ ├── RAM64.cmp │ ├── RAM64.hdl │ ├── RAM64.tst │ ├── RAM8.cmp │ ├── RAM8.hdl │ ├── RAM8.tst │ ├── Register.cmp │ ├── Register.hdl │ └── Register.tst └── b │ ├── RAM16K.cmp │ ├── RAM16K.hdl │ ├── RAM16K.tst │ ├── RAM4K.cmp │ ├── RAM4K.hdl │ ├── RAM4K.tst │ ├── RAM512.cmp │ ├── RAM512.hdl │ └── RAM512.tst ├── project04 ├── fill │ ├── Fill.asm │ ├── Fill.hack │ └── Fill.tst └── mult │ ├── Iterator.asm │ ├── Iterator.hack │ ├── Mult.asm │ ├── Mult.cmp │ ├── Mult.hack │ └── Mult.tst └── project05 ├── Add.hack ├── CPU-external.cmp ├── CPU-external.tst ├── CPU.cmp ├── CPU.hdl ├── CPU.tst ├── Computer.hdl ├── ComputerAdd-external.cmp ├── ComputerAdd-external.tst ├── ComputerAdd.cmp ├── ComputerAdd.tst ├── ComputerMax-external.cmp ├── ComputerMax-external.tst ├── ComputerMax.cmp ├── ComputerMax.tst ├── ComputerRect-external.cmp ├── ComputerRect-external.tst ├── ComputerRect.cmp ├── ComputerRect.tst ├── Max.hack ├── Memory.cmp ├── Memory.hdl ├── Memory.tst └── Rect.hack /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.out 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The Elements of Computing Systems 2 | 3 | This repository holds all of the exercises from the book _The Elements of 4 | Computing Systems_. 5 | -------------------------------------------------------------------------------- /project01/And.cmp: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0 | 0 | 0 | 3 | | 0 | 1 | 0 | 4 | | 1 | 0 | 0 | 5 | | 1 | 1 | 1 | 6 | -------------------------------------------------------------------------------- /project01/And.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/And.hdl 5 | 6 | /** 7 | * And gate: out = 1 if {a==1 and b==1}, 0 otherwise 8 | */ 9 | 10 | CHIP And { 11 | 12 | IN a, b; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here. 17 | Nand(a=a, b=b, out=nandOut); 18 | Not(in=nandOut, out=out); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /project01/And.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project01/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 | -------------------------------------------------------------------------------- /project01/And16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/And16.hdl 5 | 6 | /** 7 | * 16-bit-wise and gate: for i = 0..15: out[i] = a[i] and b[i] 8 | */ 9 | 10 | CHIP And16 { 11 | 12 | IN a[16], b[16]; 13 | OUT out[16]; 14 | 15 | PARTS: 16 | // Put your code here. 17 | And(a=a[0], b=b[0], out=out[0]); 18 | And(a=a[1], b=b[1], out=out[1]); 19 | And(a=a[2], b=b[2], out=out[2]); 20 | And(a=a[3], b=b[3], out=out[3]); 21 | And(a=a[4], b=b[4], out=out[4]); 22 | And(a=a[5], b=b[5], out=out[5]); 23 | And(a=a[6], b=b[6], out=out[6]); 24 | And(a=a[7], b=b[7], out=out[7]); 25 | And(a=a[8], b=b[8], out=out[8]); 26 | And(a=a[9], b=b[9], out=out[9]); 27 | And(a=a[10], b=b[10], out=out[10]); 28 | And(a=a[11], b=b[11], out=out[11]); 29 | And(a=a[12], b=b[12], out=out[12]); 30 | And(a=a[13], b=b[13], out=out[13]); 31 | And(a=a[14], b=b[14], out=out[14]); 32 | And(a=a[15], b=b[15], out=out[15]); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /project01/And16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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; -------------------------------------------------------------------------------- /project01/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 | -------------------------------------------------------------------------------- /project01/DMux.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/DMux.hdl 5 | 6 | /** 7 | * Dmultiplexor. 8 | * {a,b} = {in,0} if sel==0 9 | * {0,in} if sel==1 10 | */ 11 | 12 | 13 | CHIP DMux { 14 | 15 | IN in, sel; 16 | OUT a, b; 17 | 18 | PARTS: 19 | // Put your code here. 20 | // DMux = { 21 | // a = in * not(sel) 22 | // b = in * sel 23 | // } 24 | Not(in=sel, out=notSel); 25 | And(a=in, b=notSel, out=a); 26 | 27 | And(a=in, b=sel, out=b); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /project01/DMux.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project01/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 | -------------------------------------------------------------------------------- /project01/DMux4Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | 15 | CHIP DMux4Way { 16 | IN in, sel[2]; 17 | OUT a, b, c, d; 18 | 19 | PARTS: 20 | // Put your code here. 21 | DMux(in=in, sel=sel[1], a=dmux0, b=dmux1); 22 | 23 | DMux(in=dmux0, sel=sel[0], a=a, b=b); 24 | DMux(in=dmux1, sel=sel[0], a=c, b=d); 25 | } 26 | -------------------------------------------------------------------------------- /project01/DMux4Way.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project01/DMux8Way.cmp: -------------------------------------------------------------------------------- 1 | | in | sel | a | b | c | d | e | f | g | h | 2 | | 0 | 00 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | | 0 | 01 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 4 | | 0 | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 | | 0 | 11 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | | 0 | 00 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | | 0 | 01 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | | 0 | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | | 0 | 11 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | | 1 | 00 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | | 1 | 01 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 12 | | 1 | 10 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 13 | | 1 | 11 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 14 | | 1 | 00 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 15 | | 1 | 01 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 16 | | 1 | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 17 | | 1 | 11 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 18 | -------------------------------------------------------------------------------- /project01/DMux8Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | 15 | CHIP DMux8Way { 16 | IN in, sel[3]; 17 | OUT a, b, c, d, e, f, g, h; 18 | 19 | PARTS: 20 | // Put your code here. 21 | DMux(in=in, sel=sel[2], a=dmux0, b=dmux1); 22 | 23 | DMux4Way(in=dmux0, sel=sel[0..1], a=a, b=b, c=c, d=d); 24 | DMux4Way(in=dmux1, sel=sel[0..1], a=e, b=f, c=g, d=h); 25 | } 26 | -------------------------------------------------------------------------------- /project01/DMux8Way.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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.2.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 | -------------------------------------------------------------------------------- /project01/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 | -------------------------------------------------------------------------------- /project01/Mux.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/Mux.hdl 5 | 6 | /** 7 | * Multiplexor. If sel==1 then out=b else out=a. 8 | */ 9 | 10 | CHIP Mux { 11 | 12 | IN a, b, sel; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here. 17 | // Mux = Or(And(b, sel), And(a, Not(sel))) 18 | 19 | And(a=b, b=sel, out=and1); 20 | 21 | Not(in=sel, out=notSel); 22 | And(a=a, b=notSel, out=and2); 23 | 24 | Or(a=and1, b=and2, out=out); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /project01/Mux.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project01/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 | -------------------------------------------------------------------------------- /project01/Mux16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/Mux16.hdl 5 | 6 | /** 7 | * 16 bit multiplexor. If sel==1 then out=b else out=a. 8 | */ 9 | 10 | CHIP Mux16 { 11 | 12 | IN a[16], b[16], sel; 13 | OUT out[16]; 14 | 15 | PARTS: 16 | // Put your code here. 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 | } 35 | -------------------------------------------------------------------------------- /project01/Mux16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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; -------------------------------------------------------------------------------- /project01/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 | -------------------------------------------------------------------------------- /project01/Mux4Way16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | 15 | CHIP Mux4Way16 { 16 | IN a[16], b[16], c[16], d[16], sel[2]; 17 | OUT out[16]; 18 | 19 | PARTS: 20 | // Put your code here. 21 | 22 | // First selection bit 23 | Mux16(a=a, b=b, sel=sel[0], out=mux0); 24 | Mux16(a=c, b=d, sel=sel[0], out=mux1); 25 | 26 | // Second selection bit 27 | Mux16(a=mux0, b=mux1, sel=sel[1], out=out); 28 | } 29 | -------------------------------------------------------------------------------- /project01/Mux4Way16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project01/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 | -------------------------------------------------------------------------------- /project01/Mux8Way16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | 15 | CHIP Mux8Way16 { 16 | IN a[16], b[16], c[16], d[16], 17 | e[16], f[16], g[16], h[16], 18 | sel[3]; 19 | OUT out[16]; 20 | 21 | PARTS: 22 | // Put your code here. 23 | // First 2 selection bits 24 | Mux4Way16(a=a, b=b, c=c, d=d, sel=sel[0..1], out=mux0); 25 | Mux4Way16(a=e, b=f, c=g, d=h, sel=sel[0..1], out=mux1); 26 | 27 | // 3rd selection bit 28 | Mux16(a=mux0, b=mux1, sel=sel[2], out=out); 29 | } 30 | -------------------------------------------------------------------------------- /project01/Mux8Way16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project01/Not.cmp: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 0 | 1 | 3 | | 1 | 0 | 4 | -------------------------------------------------------------------------------- /project01/Not.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/Not.hdl 5 | 6 | /** 7 | * Not gate: out = not in 8 | */ 9 | 10 | CHIP Not { 11 | 12 | IN in; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here. 17 | Nand(a=in, b=in, out=out); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /project01/Not.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project01/Not16.cmp: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 0000000000000000 | 1111111111111111 | 3 | | 1111111111111111 | 0000000000000000 | 4 | | 1010101010101010 | 0101010101010101 | 5 | | 0011110011000011 | 1100001100111100 | 6 | | 0001001000110100 | 1110110111001011 | 7 | -------------------------------------------------------------------------------- /project01/Not16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/Not16.hdl 5 | 6 | /** 7 | * 16-bit Not gate: for i=0..15: out[i] = not in[i] 8 | */ 9 | 10 | CHIP Not16 { 11 | 12 | IN in[16]; 13 | OUT out[16]; 14 | 15 | PARTS: 16 | // Put your code here. 17 | Not(in=in[0], out=out[0]); 18 | Not(in=in[1], out=out[1]); 19 | Not(in=in[2], out=out[2]); 20 | Not(in=in[3], out=out[3]); 21 | Not(in=in[4], out=out[4]); 22 | Not(in=in[5], out=out[5]); 23 | Not(in=in[6], out=out[6]); 24 | Not(in=in[7], out=out[7]); 25 | Not(in=in[8], out=out[8]); 26 | Not(in=in[9], out=out[9]); 27 | Not(in=in[10], out=out[10]); 28 | Not(in=in[11], out=out[11]); 29 | Not(in=in[12], out=out[12]); 30 | Not(in=in[13], out=out[13]); 31 | Not(in=in[14], out=out[14]); 32 | Not(in=in[15], out=out[15]); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /project01/Not16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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; -------------------------------------------------------------------------------- /project01/Or.cmp: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0 | 0 | 0 | 3 | | 0 | 1 | 1 | 4 | | 1 | 0 | 1 | 5 | | 1 | 1 | 1 | 6 | -------------------------------------------------------------------------------- /project01/Or.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/Or.hdl 5 | 6 | /** 7 | * Or gate: out = 1 if {a==1 or b==1}, 0 otherwise 8 | */ 9 | 10 | CHIP Or { 11 | 12 | IN a, b; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here. 17 | // Or = Nand(Not(a), Not(b)) 18 | 19 | Not(in=a, out=notA); 20 | Not(in=b, out=notB); 21 | 22 | Nand(a=notA, b=notB, out=out); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /project01/Or.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project01/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 | -------------------------------------------------------------------------------- /project01/Or16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/Or16.hdl 5 | 6 | 7 | /** 8 | * 16-bit bitwise Or gate: for i=0..15 out[i] = a[i] or b[i]. 9 | */ 10 | 11 | CHIP Or16 { 12 | 13 | IN a[16], b[16]; 14 | OUT out[16]; 15 | 16 | PARTS: 17 | // Put your code here. 18 | Or(a=a[0], b=b[0], out=out[0]); 19 | Or(a=a[1], b=b[1], out=out[1]); 20 | Or(a=a[2], b=b[2], out=out[2]); 21 | Or(a=a[3], b=b[3], out=out[3]); 22 | Or(a=a[4], b=b[4], out=out[4]); 23 | Or(a=a[5], b=b[5], out=out[5]); 24 | Or(a=a[6], b=b[6], out=out[6]); 25 | Or(a=a[7], b=b[7], out=out[7]); 26 | Or(a=a[8], b=b[8], out=out[8]); 27 | Or(a=a[9], b=b[9], out=out[9]); 28 | Or(a=a[10], b=b[10], out=out[10]); 29 | Or(a=a[11], b=b[11], out=out[11]); 30 | Or(a=a[12], b=b[12], out=out[12]); 31 | Or(a=a[13], b=b[13], out=out[13]); 32 | Or(a=a[14], b=b[14], out=out[14]); 33 | Or(a=a[15], b=b[15], out=out[15]); 34 | } 35 | -------------------------------------------------------------------------------- /project01/Or16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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; -------------------------------------------------------------------------------- /project01/Or8Way.cmp: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 00000000 | 0 | 3 | | 11111111 | 1 | 4 | | 00010000 | 1 | 5 | | 00000001 | 1 | 6 | | 00100110 | 1 | 7 | -------------------------------------------------------------------------------- /project01/Or8Way.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/Or8Way.hdl 5 | 6 | /** 7 | * 8-way or gate: out = in[0] or in[1] or ... or in[7]. 8 | */ 9 | 10 | CHIP Or8Way { 11 | 12 | IN in[8]; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here. 17 | Or(a=in[0], b=in[1], out=out1); 18 | Or(a=out1, b=in[2], out=out2); 19 | Or(a=out2, b=in[3], out=out3); 20 | Or(a=out3, b=in[4], out=out4); 21 | Or(a=out4, b=in[5], out=out5); 22 | Or(a=out5, b=in[6], out=out6); 23 | Or(a=out6, b=in[7], out=out); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /project01/Or8Way.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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; -------------------------------------------------------------------------------- /project01/Xor.cmp: -------------------------------------------------------------------------------- 1 | | a | b | out | 2 | | 0 | 0 | 0 | 3 | | 0 | 1 | 1 | 4 | | 1 | 0 | 1 | 5 | | 1 | 1 | 0 | 6 | -------------------------------------------------------------------------------- /project01/Xor.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/01/Xor.hdl 5 | 6 | /** 7 | * Exclusive-or gate: out = !(a == b). 8 | */ 9 | 10 | CHIP Xor { 11 | 12 | IN a, b; 13 | OUT out; 14 | 15 | PARTS: 16 | // Put your code here. 17 | // Or = Nand(Not(a), Not(b)) 18 | // Xor = Or(And(Not(a), b), And(a, Not(b))) 19 | 20 | Not(in=a, out=notA); 21 | And(a=notA, b=b, out=and1); 22 | 23 | Not(in=b, out=notB); 24 | And(a=a, b=notB, out=and2); 25 | 26 | Or(a=and1, b=and2, out=out); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /project01/Xor.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project02.5/ClkRSLatch.hdl: -------------------------------------------------------------------------------- 1 | CHIP ClkRSLatch { 2 | 3 | // The conventional abbreviation for the clock input is 'clk' 4 | // but there is a bug in the Hardware Simulator that confuses 5 | // that signal name with the internal DFF clock. 6 | 7 | IN s, r, ck; 8 | OUT q, q-; 9 | 10 | PARTS: 11 | SNand(a=s, b=ck, out=s-); 12 | SNand(a=r, b=ck, out=r-); 13 | SNand(a=s-, b=qq-, out=q, out=qq); 14 | SNand(a=r-, b=qq, out=q-, out=qq-); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /project02.5/ClkRSLatch.tst: -------------------------------------------------------------------------------- 1 | load ClkRSLatch.hdl, 2 | output-file ClkRSLatch.out, 3 | 4 | // Important: the latch must be initialized set or reset 5 | set s 0, 6 | set r 1, 7 | set ck 1, 8 | repeat 5 { tick, tock; } 9 | set ck 0, 10 | repeat 5 { tick, tock; } 11 | 12 | output-list time%S1.4.1 s%B2.1.2 r%B2.1.2 ck%B2.1.2 s-%B2.1.2 r-%B2.1.2 q%B2.1.2 q-%B2.1.2; 13 | 14 | // Hold 15 | set ck 0, 16 | set s 0, 17 | set r 0, 18 | repeat 4 { tick, output; tock, output; } 19 | 20 | // Ignore s 21 | set s 1, 22 | repeat 2 { tick, output; tock, output; } 23 | 24 | // Ignore s+r 25 | set r 1, 26 | repeat 2 { tick, output; tock, output; } 27 | 28 | // Ignore r 29 | set s 0, 30 | set r 1, 31 | repeat 2 { tick, output; tock, output; } 32 | 33 | set r 0, 34 | repeat 2 { tick, output; tock, output; } 35 | 36 | output-list time%S1.4.1 s%B2.1.2 r%B2.1.2 ck%B2.1.2 s-%B2.1.2 r-%B2.1.2 q%B2.1.2 q-%B2.1.2; 37 | 38 | // Set 39 | set ck 1, 40 | repeat 2 { tick, output; tock, output; } 41 | set s 1, 42 | repeat 4 { tick, output; tock, output; } 43 | 44 | // Hold 45 | set s 0, 46 | repeat 4 { tick, output; tock, output; } 47 | 48 | output-list time%S1.4.1 s%B2.1.2 r%B2.1.2 ck%B2.1.2 s-%B2.1.2 r-%B2.1.2 q%B2.1.2 q-%B2.1.2; 49 | 50 | // Reset 51 | set r 1, 52 | repeat 4 { tick, output; tock, output; } 53 | 54 | // Hold 55 | set ck 0, 56 | repeat 2 { tick, output; tock, output; } 57 | set r 0, 58 | repeat 2 { tick, output; tock, output; } 59 | set s 1, 60 | repeat 4 { tick, output; tock, output; } 61 | 62 | output-list time%S1.4.1 s%B2.1.2 r%B2.1.2 ck%B2.1.2 s-%B2.1.2 r-%B2.1.2 q%B2.1.2 q-%B2.1.2; 63 | 64 | -------------------------------------------------------------------------------- /project02.5/DFFn.hdl: -------------------------------------------------------------------------------- 1 | CHIP DFFn { 2 | 3 | // The conventional abbreviation for the clock input is 'clk' 4 | // but there is a bug in the Hardware Simulator that confuses 5 | // that signal name with the internal DFF clock. 6 | 7 | IN d, ck; 8 | OUT q, q-; 9 | 10 | PARTS: 11 | SNand(a=d, b=ck, out=s1-); 12 | SNand(a=s1-, b=ck, out=r1-); 13 | SNand(a=s1-, b=q1-, out=q1); 14 | SNand(a=r1-, b=q1, out=q1-); 15 | SNot(in=ck, out=ck-); 16 | SNand(a=q1, b=ck-, out=s2-); 17 | SNand(a=q1-, b=ck-, out=r2-); 18 | SNand(a=s2-, b=q2-, out=q2, out=q); 19 | SNand(a=r2-, b=q2, out=q2-, out=q-); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /project02.5/DFFn.tst: -------------------------------------------------------------------------------- 1 | load DFFn.hdl, 2 | output-file DFFn.out, 3 | 4 | // Important: the latch must be initialized set or reset 5 | set d 0, 6 | set ck 1, 7 | repeat 5 { tick, tock; } 8 | set ck 0, 9 | repeat 5 { tick, tock; } 10 | 11 | 12 | output-list time%S1.4.1 d%B2.1.2 ck%B2.1.2 s1-%B2.1.2 r1-%B2.1.2 13 | q1%B2.1.2 q1-%B2.1.2 ck-%B2.1.2 s2-%B2.1.2 r2-%B2.1.2 q%B2.1.2 q-%B2.1.2; 14 | 15 | // Hold master FF -- d ignored 16 | set ck 0, 17 | set d 1, 18 | repeat 4 { tick, output; tock, output; } 19 | 20 | set d 0, 21 | repeat 4 { tick, output; tock, output; } 22 | 23 | 24 | output-list time%S1.4.1 d%B2.1.2 ck%B2.1.2 s1-%B2.1.2 r1-%B2.1.2 25 | q1%B2.1.2 q1-%B2.1.2 ck-%B2.1.2 s2-%B2.1.2 r2-%B2.1.2 q%B2.1.2 q-%B2.1.2; 26 | 27 | // Set master FF -- clk before d 28 | set ck 1, 29 | repeat 2 { tick, output; tock, output; } 30 | set d 1, 31 | repeat 4 { tick, output; tock, output; } 32 | 33 | // Transfer to slave FF 34 | set ck 0, 35 | repeat 5 { tick, output; tock, output; } 36 | 37 | 38 | output-list time%S1.4.1 d%B2.1.2 ck%B2.1.2 s1-%B2.1.2 r1-%B2.1.2 39 | q1%B2.1.2 q1-%B2.1.2 ck-%B2.1.2 s2-%B2.1.2 r2-%B2.1.2 q%B2.1.2 q-%B2.1.2; 40 | 41 | // Reset master FF -- d before clk 42 | set d 0, 43 | repeat 2 { tick, output; tock, output; } 44 | set ck 1, 45 | repeat 4 { tick, output; tock, output; } 46 | 47 | // Transfer to slave FF 48 | set ck 0, 49 | repeat 5 { tick, output; tock, output; } 50 | 51 | output-list time%S1.4.1 d%B2.1.2 ck%B2.1.2 s1-%B2.1.2 r1-%B2.1.2 52 | q1%B2.1.2 q1-%B2.1.2 ck-%B2.1.2 s2-%B2.1.2 r2-%B2.1.2 q%B2.1.2 q-%B2.1.2; 53 | 54 | -------------------------------------------------------------------------------- /project02.5/RSFF.hdl: -------------------------------------------------------------------------------- 1 | CHIP RSFF { 2 | 3 | // The conventional abbreviation for the clock input is 'clk' 4 | // but there is a bug in the Hardware Simulator that confuses 5 | // that signal name with the internal DFF clock. 6 | 7 | IN s, r, ck; 8 | OUT q, q-; 9 | 10 | PARTS: 11 | SNand(a=s, b=ck, out=s1-); 12 | SNand(a=r, b=ck, out=r1-); 13 | SNand(a=s1-, b=q1-, out=q1); 14 | SNand(a=r1-, b=q1, out=q1-); 15 | SNot(in=ck, out=ck-); 16 | SNand(a=q1, b=ck-, out=s2-); 17 | SNand(a=q1-, b=ck-, out=r2-); 18 | SNand(a=s2-, b=q2-, out=q2, out=q); 19 | SNand(a=r2-, b=q2, out=q2-, out=q-); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /project02.5/RSFF.tst: -------------------------------------------------------------------------------- 1 | load RSFF.hdl, 2 | output-file RSFF.out, 3 | 4 | // Important: the latch must be initialized set or reset 5 | set s 0, 6 | set r 1, 7 | set ck 1, 8 | repeat 5 { tick, tock; } 9 | set r 0, 10 | set ck 0, 11 | repeat 5 { tick, tock; } 12 | 13 | output-list time%S1.4.1 s%B2.1.2 r%B2.1.2 ck%B2.1.2 s1-%B2.1.2 r1-%B2.1.2 14 | q1%B2.1.2 q1-%B2.1.2 ck-%B2.1.2 s2-%B2.1.2 r2-%B2.1.2 q%B2.1.2 q-%B2.1.2; 15 | 16 | // Hold 17 | set ck 0, 18 | set s 0, 19 | set r 0, 20 | 21 | tick, output; tock, output; 22 | 23 | // set pulse while clock high 24 | set ck 1, 25 | repeat 2 { tick, output; tock, output; } 26 | set s 1, 27 | repeat 4 { tick, output; tock, output; } 28 | set s 0, 29 | tick, output; tock, output; 30 | set ck 0, 31 | repeat 5 { tick, output; tock, output; } 32 | 33 | output-list time%S1.4.1 s%B2.1.2 r%B2.1.2 ck%B2.1.2 s1-%B2.1.2 r1-%B2.1.2 34 | q1%B2.1.2 q1-%B2.1.2 ck-%B2.1.2 s2-%B2.1.2 r2-%B2.1.2 q%B2.1.2 q-%B2.1.2; 35 | 36 | // clock pulse while reset high 37 | set r 1, 38 | repeat 2 { tick, output; tock, output; } 39 | set ck 1, 40 | repeat 4 { tick, output; tock, output; } 41 | set ck 0, 42 | tick, output; tock, output; 43 | set r 0, 44 | repeat 5 { tick, output; tock, output; } 45 | 46 | output-list time%S1.4.1 s%B2.1.2 r%B2.1.2 ck%B2.1.2 s1-%B2.1.2 r1-%B2.1.2 47 | q1%B2.1.2 q1-%B2.1.2 ck-%B2.1.2 s2-%B2.1.2 r2-%B2.1.2 q%B2.1.2 q-%B2.1.2; 48 | 49 | 50 | -------------------------------------------------------------------------------- /project02.5/RSLatch.hdl: -------------------------------------------------------------------------------- 1 | CHIP RSLatch { 2 | IN s-, r-; 3 | OUT q, q-; 4 | 5 | PARTS: 6 | SNand(a=s-, b=qq-, out=qq, out=q); 7 | SNand(a=r-, b=qq, out=qq-, out=q-); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /project02.5/RSLatch.tst: -------------------------------------------------------------------------------- 1 | load RSLatch.hdl, 2 | output-file RSLatch.out, 3 | output-list time%S1.4.1 s-%B2.1.2 r-%B2.1.2 q%B2.1.2 q-%B2.1.2; 4 | 5 | // Important: the latch must be initialized set or reset 6 | set s- 1, 7 | set r- 0, 8 | repeat 10 { tick, tock; } 9 | 10 | // Hold 11 | set s- 1, 12 | set r- 1, 13 | repeat 4 { tick, output; tock, output; } 14 | 15 | // Set 16 | set s- 0, 17 | repeat 4 { tick, output; tock, output; } 18 | 19 | output-list time%S1.4.1 s-%B2.1.2 r-%B2.1.2 q%B2.1.2 q-%B2.1.2; 20 | 21 | // Hold 22 | set s- 1, 23 | repeat 4 { tick, output; tock, output; } 24 | 25 | // Reset 26 | set r- 0, 27 | repeat 4 { tick, output; tock, output; } 28 | 29 | output-list time%S1.4.1 s-%B2.1.2 r-%B2.1.2 q%B2.1.2 q-%B2.1.2; 30 | 31 | // Hold 32 | set r- 1, 33 | repeat 4 { tick, output; tock, output; } 34 | 35 | // Set 36 | set s- 0, 37 | repeat 2 { tick, output; tock, output; } 38 | 39 | // Set and Reset -- illegal 40 | set r- 0, 41 | repeat 4 { tick, output; tock, output; } 42 | 43 | // Hold, but simulated circuit oscillates 44 | set s- 1, 45 | set r- 1, 46 | 47 | repeat 4 { tick, output; tock, output; } 48 | output-list time%S1.4.1 s-%B2.1.2 r-%B2.1.2 q%B2.1.2 q-%B2.1.2; 49 | 50 | -------------------------------------------------------------------------------- /project02.5/SNand.hdl: -------------------------------------------------------------------------------- 1 | CHIP SNand { 2 | IN a, b; 3 | OUT out; 4 | 5 | PARTS: 6 | Nand(a=a, b=b, out=x); 7 | DFF(in=x, out=out); 8 | } 9 | -------------------------------------------------------------------------------- /project02.5/SNot.hdl: -------------------------------------------------------------------------------- 1 | /// SNot -- Synchronized Not gate 2 | 3 | CHIP SNot { 4 | 5 | IN in; 6 | OUT out; 7 | 8 | PARTS: 9 | Not(in=in, out=x); 10 | DFF(in=x, out=out); 11 | } 12 | -------------------------------------------------------------------------------- /project02/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 | -------------------------------------------------------------------------------- /project02/ALU.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/02/ALU.hdl 5 | 6 | /** 7 | * The ALU. Computes one of the following functions: 8 | * x+y, x-y, y&x, 0, 1, -1, x, y, -x, -y, !x, !y, 9 | * x+1, y+1, x-1, y-1, x&y, x|y on two 16-bit inputs, 10 | * according to 6 input bits denoted zx,nx,zy,ny,f,no. 11 | * The bit-combinations that yield each function are 12 | * documented in the book. In addition, the ALU 13 | * computes two 1-bit outputs: if the ALU output 14 | * is 0, zr is set to 1; otherwise zr is set to 0; 15 | * If out<0, ng is set to 1; otherwise ng is set to 0. 16 | */ 17 | 18 | // Implementation: the ALU manipulates the x and y 19 | // inputs and then operates on the resulting values, 20 | // as follows: 21 | // if (zx==1) set x = 0 // 16-bit constant 22 | // if (nx==1) set x = ~x // bitwise "not" 23 | // if (zy==1) set y = 0 // 16-bit constant 24 | // if (ny==1) set y = ~y // bitwise "not" 25 | // if (f==1) set out = x + y // integer 2's complement addition 26 | // if (f==0) set out = x & y // bitwise "and" 27 | // if (no==1) set out = ~out // bitwise "not" 28 | // if (out==0) set zr = 1 29 | // if (out<0) set ng = 1 30 | 31 | 32 | CHIP ALU { 33 | IN 34 | x[16], y[16], // 16-bit inputs 35 | zx, // zero the x input? 36 | nx, // negate the x input? 37 | zy, // zero the y input? 38 | ny, // negate the y input? 39 | f, // compute out = x + y (if 1) or out = x & y (if 0) 40 | no; // negate the out output? 41 | 42 | OUT 43 | out[16], // 16-bit output 44 | zr, // 1 if (out==0), 0 otherwise 45 | ng; // 1 if (out<0), 0 otherwise 46 | 47 | PARTS: 48 | // ----- Zero x (zx bit) 49 | // If the zx bit is set, the muxer will select 16 bits of 0, 50 | // otherwise it will select x 51 | Mux16(a=x, b=false, sel=zx, out=zxOut); 52 | 53 | // ----- Negate x (nx bit) 54 | // Negate x with Not16. Then use Mux16 to select between negated x 55 | // or the previous output (zxOut). 56 | Not16(in=zxOut, out=notX); 57 | Mux16(a=zxOut, b=notX, sel=nx, out=nxOut); 58 | 59 | // ----- Zero y (zy bit) 60 | // Exactly the same as zero x. 61 | Mux16(a=y, b=false, sel=zy, out=zyOut); 62 | 63 | // ----- Negate y (zy bit) 64 | // Behaves exactly the same as Negate x. 65 | Not16(in=zyOut, out=notY); 66 | Mux16(a=zyOut, b=notY, sel=ny, out=nyOut); 67 | 68 | // ----- Compute out (f bit) 69 | // x & y 70 | And16(a=nxOut, b=nyOut, out=andOut); 71 | 72 | // x + y 73 | Add16(a=nxOut, b=nyOut, out=addOut); 74 | 75 | // Return the output that the f bit expects 76 | Mux16(a=andOut, b=addOut, sel=f, out=fOut); 77 | 78 | // ----- Negate output (no bit) 79 | // Simply negate the output if this bit is set. This operation returns 80 | // the final output. 81 | Not16(in=fOut, out=noOut); 82 | Mux16(a=fOut, b=noOut, sel=no, out=final); 83 | 84 | // Need out final mux so that we can save the final output and run a few 85 | // tests on it below. 86 | Mux16(a=final, b=false, sel=false, out=out); 87 | 88 | // ----- Return true if the output is zero (zr) 89 | // Or over all 16 bits. This will return false if the number is zero, 90 | // so flip the bit so that zr is true 91 | Or16Way(in=final, out=zrOut); 92 | Not(in=zrOut, out=zr); 93 | 94 | // ----- Return true if the output is negative (ng) 95 | // The most significant bit will be 1 if the number is negative thanks to 96 | // 2's complement. But I abstracted all of that out into another chip. 97 | IsNeg(in=final, out=ng); 98 | 99 | } 100 | 101 | -------------------------------------------------------------------------------- /project02/ALU.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project02/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 | -------------------------------------------------------------------------------- /project02/Add16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/02/Adder16.hdl 5 | 6 | /* 7 | * Adds two 16-bit values. 8 | * The most-significant carry bit is ignored. 9 | */ 10 | 11 | CHIP Add16 { 12 | IN a[16], b[16]; 13 | OUT out[16]; 14 | 15 | PARTS: 16 | // First bit can be a half adder because there is no carry to worry about carrying over 17 | HalfAdder(a=a[0], b=b[0], sum=out[0], carry=carry1); 18 | FullAdder(a=a[1], b=b[1], c=carry1, sum=out[1], carry=carry2); 19 | FullAdder(a=a[2], b=b[2], c=carry2, sum=out[2], carry=carry3); 20 | FullAdder(a=a[3], b=b[3], c=carry3, sum=out[3], carry=carry4); 21 | FullAdder(a=a[4], b=b[4], c=carry4, sum=out[4], carry=carry5); 22 | FullAdder(a=a[5], b=b[5], c=carry5, sum=out[5], carry=carry6); 23 | FullAdder(a=a[6], b=b[6], c=carry6, sum=out[6], carry=carry7); 24 | FullAdder(a=a[7], b=b[7], c=carry7, sum=out[7], carry=carry8); 25 | FullAdder(a=a[8], b=b[8], c=carry8, sum=out[8], carry=carry9); 26 | FullAdder(a=a[9], b=b[9], c=carry9, sum=out[9], carry=carry10); 27 | FullAdder(a=a[10], b=b[10], c=carry10, sum=out[10], carry=carry11); 28 | FullAdder(a=a[11], b=b[11], c=carry11, sum=out[11], carry=carry12); 29 | FullAdder(a=a[12], b=b[12], c=carry12, sum=out[12], carry=carry13); 30 | FullAdder(a=a[13], b=b[13], c=carry13, sum=out[13], carry=carry14); 31 | FullAdder(a=a[14], b=b[14], c=carry14, sum=out[14], carry=carry15); 32 | FullAdder(a=a[15], b=b[15], c=carry15, sum=out[15], carry=carry16); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /project02/Add16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project02/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 | -------------------------------------------------------------------------------- /project02/FullAdder.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | HalfAdder(a=a, b=b, sum=sum1, carry=carry1); 17 | HalfAdder(a=sum1, b=c, sum=sum, carry=carry2); 18 | 19 | // figure out if there is a carry 20 | Or(a=carry1, b=carry2, out=carry); 21 | } 22 | -------------------------------------------------------------------------------- /project02/FullAdder.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project02/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 | -------------------------------------------------------------------------------- /project02/HalfAdder.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | // Sum 17 | Xor(a=a, b=b, out=sum); 18 | 19 | // Carry 20 | And(a=a, b=b, out=carry); 21 | } 22 | -------------------------------------------------------------------------------- /project02/HalfAdder.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project02/Inc16.cmp: -------------------------------------------------------------------------------- 1 | | in | out | 2 | | 0000000000000000 | 0000000000000001 | 3 | | 1111111111111111 | 0000000000000000 | 4 | | 0000000000000101 | 0000000000000110 | 5 | | 1111111111111011 | 1111111111111100 | 6 | -------------------------------------------------------------------------------- /project02/Inc16.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/02/Inc16.hdl 5 | 6 | /** 7 | * 16-bit incrementer: out = in + 1 (arithmetic addition) 8 | */ 9 | 10 | CHIP Inc16 { 11 | IN in[16]; 12 | OUT out[16]; 13 | 14 | PARTS: 15 | // Pass in a and 0000000000000001, represented as 15 falses and 1 true 16 | Add16(a=in, b[0]=true, b[1..15]=false, out=out); 17 | } 18 | -------------------------------------------------------------------------------- /project02/Inc16.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project02/IsNeg.hdl: -------------------------------------------------------------------------------- 1 | // Another gate that wasn't in the book but came in handy 2 | // 3 | 4 | /** 5 | * Return 1 if the highest bit is 1, indicating a negative 6 | * number in 2's complement 7 | */ 8 | 9 | CHIP IsNeg { 10 | 11 | IN in[16]; 12 | OUT out; 13 | 14 | PARTS: 15 | Or(a=in[15], b=false, out=out); 16 | } 17 | -------------------------------------------------------------------------------- /project02/Or16Way.hdl: -------------------------------------------------------------------------------- 1 | // This gate wasn't in the book, but I needed it for my ALU. 2 | // 3 | 4 | /** 5 | * 16-way or gate: out = in[0] or in[1] or ... or in[15]. 6 | */ 7 | 8 | CHIP Or16Way { 9 | 10 | IN in[16]; 11 | OUT out; 12 | 13 | PARTS: 14 | Or8Way(in=in[0..7], out=or1); 15 | Or8Way(in=in[8..15], out=or2); 16 | Or(a=or1, b=or2, out=out); 17 | } 18 | -------------------------------------------------------------------------------- /project03/a/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 | -------------------------------------------------------------------------------- /project03/a/Bit.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | // Put your code here. 18 | Mux(a=dffOut, b=in, sel=load, out=muxOut); 19 | DFF(in=muxOut, out=dffOut, out=out); 20 | } 21 | -------------------------------------------------------------------------------- /project03/a/Bit.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/03/a/Bit.tst 5 | 6 | load Bit.hdl, 7 | output-file Bit.out, 8 | compare-to Bit.cmp, 9 | output-list time%S1.4.1 in%B2.1.2 load%B2.1.2 out%B2.1.2; 10 | 11 | set in 0, 12 | set load 0, 13 | tick, 14 | output; 15 | 16 | tock, 17 | output; 18 | 19 | set in 0, 20 | set load 1, 21 | tick, 22 | output; 23 | 24 | tock, 25 | output; 26 | 27 | set in 1, 28 | set load 0, 29 | tick, 30 | output; 31 | 32 | tock, 33 | output; 34 | 35 | set in 1, 36 | set load 1, 37 | tick, 38 | output; 39 | 40 | tock, 41 | output; 42 | 43 | set in 0, 44 | set load 0, 45 | tick, 46 | output; 47 | 48 | tock, 49 | output; 50 | 51 | set in 1, 52 | set load 0, 53 | tick, 54 | output; 55 | 56 | tock, 57 | output; 58 | 59 | set in 0, 60 | set load 1, 61 | tick, 62 | output; 63 | 64 | tock, 65 | output; 66 | 67 | set in 1, 68 | set load 1, 69 | tick, 70 | output; 71 | 72 | tock, 73 | output; 74 | 75 | set in 0, 76 | set load 0, 77 | tick, 78 | output; 79 | 80 | tock, 81 | output; 82 | 83 | set in 0, 84 | set load 0, 85 | tick, 86 | output; 87 | 88 | tock, 89 | output; 90 | 91 | set in 0, 92 | set load 0, 93 | tick, 94 | output; 95 | 96 | tock, 97 | output; 98 | 99 | set in 0, 100 | set load 0, 101 | tick, 102 | output; 103 | 104 | tock, 105 | output; 106 | 107 | set in 0, 108 | set load 0, 109 | tick, 110 | output; 111 | 112 | tock, 113 | output; 114 | 115 | set in 0, 116 | set load 0, 117 | tick, 118 | output; 119 | 120 | tock, 121 | output; 122 | 123 | set in 0, 124 | set load 0, 125 | tick, 126 | output; 127 | 128 | tock, 129 | output; 130 | 131 | set in 0, 132 | set load 0, 133 | tick, 134 | output; 135 | 136 | tock, 137 | output; 138 | 139 | set in 0, 140 | set load 0, 141 | tick, 142 | output; 143 | 144 | tock, 145 | output; 146 | 147 | set in 0, 148 | set load 0, 149 | tick, 150 | output; 151 | 152 | tock, 153 | output; 154 | 155 | set in 0, 156 | set load 0, 157 | tick, 158 | output; 159 | 160 | tock, 161 | output; 162 | 163 | set in 0, 164 | set load 0, 165 | tick, 166 | output; 167 | 168 | tock, 169 | output; 170 | 171 | set in 0, 172 | set load 0, 173 | tick, 174 | output; 175 | 176 | tock, 177 | output; 178 | 179 | set in 0, 180 | set load 0, 181 | tick, 182 | output; 183 | 184 | tock, 185 | output; 186 | 187 | set in 0, 188 | set load 0, 189 | tick, 190 | output; 191 | 192 | tock, 193 | output; 194 | 195 | set in 0, 196 | set load 0, 197 | tick, 198 | output; 199 | 200 | tock, 201 | output; 202 | 203 | set in 0, 204 | set load 0, 205 | tick, 206 | output; 207 | 208 | tock, 209 | output; 210 | 211 | set in 0, 212 | set load 0, 213 | tick, 214 | output; 215 | 216 | tock, 217 | output; 218 | 219 | set in 0, 220 | set load 0, 221 | tick, 222 | output; 223 | 224 | tock, 225 | output; 226 | 227 | set in 0, 228 | set load 0, 229 | tick, 230 | output; 231 | 232 | tock, 233 | output; 234 | 235 | set in 0, 236 | set load 0, 237 | tick, 238 | output; 239 | 240 | tock, 241 | output; 242 | 243 | set in 0, 244 | set load 0, 245 | tick, 246 | output; 247 | 248 | tock, 249 | output; 250 | 251 | set in 0, 252 | set load 0, 253 | tick, 254 | output; 255 | 256 | tock, 257 | output; 258 | 259 | set in 0, 260 | set load 0, 261 | tick, 262 | output; 263 | 264 | tock, 265 | output; 266 | 267 | set in 0, 268 | set load 0, 269 | tick, 270 | output; 271 | 272 | tock, 273 | output; 274 | 275 | set in 0, 276 | set load 0, 277 | tick, 278 | output; 279 | 280 | tock, 281 | output; 282 | 283 | set in 0, 284 | set load 0, 285 | tick, 286 | output; 287 | 288 | tock, 289 | output; 290 | 291 | set in 0, 292 | set load 0, 293 | tick, 294 | output; 295 | 296 | tock, 297 | output; 298 | 299 | set in 0, 300 | set load 0, 301 | tick, 302 | output; 303 | 304 | tock, 305 | output; 306 | 307 | set in 0, 308 | set load 0, 309 | tick, 310 | output; 311 | 312 | tock, 313 | output; 314 | 315 | set in 0, 316 | set load 0, 317 | tick, 318 | output; 319 | 320 | tock, 321 | output; 322 | 323 | set in 0, 324 | set load 0, 325 | tick, 326 | output; 327 | 328 | tock, 329 | output; 330 | 331 | set in 0, 332 | set load 0, 333 | tick, 334 | output; 335 | 336 | tock, 337 | output; 338 | 339 | set in 0, 340 | set load 0, 341 | tick, 342 | output; 343 | 344 | tock, 345 | output; 346 | 347 | set in 0, 348 | set load 0, 349 | tick, 350 | output; 351 | 352 | tock, 353 | output; 354 | 355 | set in 0, 356 | set load 0, 357 | tick, 358 | output; 359 | 360 | tock, 361 | output; 362 | 363 | set in 0, 364 | set load 0, 365 | tick, 366 | output; 367 | 368 | tock, 369 | output; 370 | 371 | set in 0, 372 | set load 0, 373 | tick, 374 | output; 375 | 376 | tock, 377 | output; 378 | 379 | set in 0, 380 | set load 0, 381 | tick, 382 | output; 383 | 384 | tock, 385 | output; 386 | 387 | set in 0, 388 | set load 0, 389 | tick, 390 | output; 391 | 392 | tock, 393 | output; 394 | 395 | set in 0, 396 | set load 0, 397 | tick, 398 | output; 399 | 400 | tock, 401 | output; 402 | 403 | set in 0, 404 | set load 0, 405 | tick, 406 | output; 407 | 408 | tock, 409 | output; 410 | 411 | set in 0, 412 | set load 0, 413 | tick, 414 | output; 415 | 416 | tock, 417 | output; 418 | 419 | set in 0, 420 | set load 0, 421 | tick, 422 | output; 423 | 424 | tock, 425 | output; 426 | 427 | set in 0, 428 | set load 0, 429 | tick, 430 | output; 431 | 432 | tock, 433 | output; 434 | 435 | set in 0, 436 | set load 0, 437 | tick, 438 | output; 439 | 440 | tock, 441 | output; 442 | 443 | set in 0, 444 | set load 0, 445 | tick, 446 | output; 447 | 448 | tock, 449 | output; 450 | 451 | set in 0, 452 | set load 0, 453 | tick, 454 | output; 455 | 456 | tock, 457 | output; 458 | 459 | set in 0, 460 | set load 0, 461 | tick, 462 | output; 463 | 464 | tock, 465 | output; 466 | 467 | set in 0, 468 | set load 1, 469 | tick, 470 | output; 471 | 472 | tock, 473 | output; 474 | 475 | set in 1, 476 | set load 0, 477 | tick, 478 | output; 479 | 480 | tock, 481 | output; 482 | 483 | set in 1, 484 | set load 0, 485 | tick, 486 | output; 487 | 488 | tock, 489 | output; 490 | 491 | set in 1, 492 | set load 0, 493 | tick, 494 | output; 495 | 496 | tock, 497 | output; 498 | 499 | set in 1, 500 | set load 0, 501 | tick, 502 | output; 503 | 504 | tock, 505 | output; 506 | 507 | set in 1, 508 | set load 0, 509 | tick, 510 | output; 511 | 512 | tock, 513 | output; 514 | 515 | set in 1, 516 | set load 0, 517 | tick, 518 | output; 519 | 520 | tock, 521 | output; 522 | 523 | set in 1, 524 | set load 0, 525 | tick, 526 | output; 527 | 528 | tock, 529 | output; 530 | 531 | set in 1, 532 | set load 0, 533 | tick, 534 | output; 535 | 536 | tock, 537 | output; 538 | 539 | set in 1, 540 | set load 0, 541 | tick, 542 | output; 543 | 544 | tock, 545 | output; 546 | 547 | set in 1, 548 | set load 0, 549 | tick, 550 | output; 551 | 552 | tock, 553 | output; 554 | 555 | set in 1, 556 | set load 0, 557 | tick, 558 | output; 559 | 560 | tock, 561 | output; 562 | 563 | set in 1, 564 | set load 0, 565 | tick, 566 | output; 567 | 568 | tock, 569 | output; 570 | 571 | set in 1, 572 | set load 0, 573 | tick, 574 | output; 575 | 576 | tock, 577 | output; 578 | 579 | set in 1, 580 | set load 0, 581 | tick, 582 | output; 583 | 584 | tock, 585 | output; 586 | 587 | set in 1, 588 | set load 0, 589 | tick, 590 | output; 591 | 592 | tock, 593 | output; 594 | 595 | set in 1, 596 | set load 0, 597 | tick, 598 | output; 599 | 600 | tock, 601 | output; 602 | 603 | set in 1, 604 | set load 0, 605 | tick, 606 | output; 607 | 608 | tock, 609 | output; 610 | 611 | set in 1, 612 | set load 0, 613 | tick, 614 | output; 615 | 616 | tock, 617 | output; 618 | 619 | set in 1, 620 | set load 0, 621 | tick, 622 | output; 623 | 624 | tock, 625 | output; 626 | 627 | set in 1, 628 | set load 0, 629 | tick, 630 | output; 631 | 632 | tock, 633 | output; 634 | 635 | set in 1, 636 | set load 0, 637 | tick, 638 | output; 639 | 640 | tock, 641 | output; 642 | 643 | set in 1, 644 | set load 0, 645 | tick, 646 | output; 647 | 648 | tock, 649 | output; 650 | 651 | set in 1, 652 | set load 0, 653 | tick, 654 | output; 655 | 656 | tock, 657 | output; 658 | 659 | set in 1, 660 | set load 0, 661 | tick, 662 | output; 663 | 664 | tock, 665 | output; 666 | 667 | set in 1, 668 | set load 0, 669 | tick, 670 | output; 671 | 672 | tock, 673 | output; 674 | 675 | set in 1, 676 | set load 0, 677 | tick, 678 | output; 679 | 680 | tock, 681 | output; 682 | 683 | set in 1, 684 | set load 0, 685 | tick, 686 | output; 687 | 688 | tock, 689 | output; 690 | 691 | set in 1, 692 | set load 0, 693 | tick, 694 | output; 695 | 696 | tock, 697 | output; 698 | 699 | set in 1, 700 | set load 0, 701 | tick, 702 | output; 703 | 704 | tock, 705 | output; 706 | 707 | set in 1, 708 | set load 0, 709 | tick, 710 | output; 711 | 712 | tock, 713 | output; 714 | 715 | set in 1, 716 | set load 0, 717 | tick, 718 | output; 719 | 720 | tock, 721 | output; 722 | 723 | set in 1, 724 | set load 0, 725 | tick, 726 | output; 727 | 728 | tock, 729 | output; 730 | 731 | set in 1, 732 | set load 0, 733 | tick, 734 | output; 735 | 736 | tock, 737 | output; 738 | 739 | set in 1, 740 | set load 0, 741 | tick, 742 | output; 743 | 744 | tock, 745 | output; 746 | 747 | set in 1, 748 | set load 0, 749 | tick, 750 | output; 751 | 752 | tock, 753 | output; 754 | 755 | set in 1, 756 | set load 0, 757 | tick, 758 | output; 759 | 760 | tock, 761 | output; 762 | 763 | set in 1, 764 | set load 0, 765 | tick, 766 | output; 767 | 768 | tock, 769 | output; 770 | 771 | set in 1, 772 | set load 0, 773 | tick, 774 | output; 775 | 776 | tock, 777 | output; 778 | 779 | set in 1, 780 | set load 0, 781 | tick, 782 | output; 783 | 784 | tock, 785 | output; 786 | 787 | set in 1, 788 | set load 0, 789 | tick, 790 | output; 791 | 792 | tock, 793 | output; 794 | 795 | set in 1, 796 | set load 0, 797 | tick, 798 | output; 799 | 800 | tock, 801 | output; 802 | 803 | set in 1, 804 | set load 0, 805 | tick, 806 | output; 807 | 808 | tock, 809 | output; 810 | 811 | set in 1, 812 | set load 0, 813 | tick, 814 | output; 815 | 816 | tock, 817 | output; 818 | 819 | set in 1, 820 | set load 0, 821 | tick, 822 | output; 823 | 824 | tock, 825 | output; 826 | 827 | set in 1, 828 | set load 0, 829 | tick, 830 | output; 831 | 832 | tock, 833 | output; 834 | 835 | set in 1, 836 | set load 0, 837 | tick, 838 | output; 839 | 840 | tock, 841 | output; 842 | 843 | set in 1, 844 | set load 0, 845 | tick, 846 | output; 847 | 848 | tock, 849 | output; 850 | 851 | set in 1, 852 | set load 0, 853 | tick, 854 | output; 855 | 856 | tock, 857 | output; 858 | 859 | set in 1, 860 | set load 0, 861 | tick, 862 | output; 863 | 864 | tock, 865 | output; 866 | -------------------------------------------------------------------------------- /project03/a/PC.cmp: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /project03/a/PC.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | // Put your code here. 20 | 21 | // Pin priority: reset, load, inc 22 | 23 | // If inc bit is set, take the value from last cycle's Add16, 24 | // otherwise just take the Register's output from last cycle. 25 | Mux16(a=regOut, b=addOut, sel=inc, out=incrementOut); 26 | 27 | // If load bit is set, take the input, otherwise take the value 28 | // from the inc mux. 29 | Mux16(a=incrementOut, b=in, sel=load, out=loadOut); 30 | 31 | // If reset bit is set take 0, otherwise take the value 32 | // from the load mux. 33 | Mux16(a=loadOut, b=false, sel=reset, out=regIn); 34 | 35 | // NOTE: probably can do it like this, but i'm tired 36 | // Mux4Way16(a=regOut, b=addOut, c=in, d=false, sel=something, out=regIn); 37 | 38 | // Storage element for the counter 39 | // Note that load bit is always set because we want to update the 40 | // stored value every clock cycle. Also note that the out bus is sent 41 | // to out, and fed back into the chip for the next cycle. 42 | Register(in=regIn, load=true, out=regOut, out=out); 43 | 44 | // Add 1 to the output of the Register and feed the result back 45 | // for the next clock cycle. 46 | Add16(a=regOut, b[0]=true, out=addOut); 47 | 48 | } 49 | 50 | -------------------------------------------------------------------------------- /project03/a/PC.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project03/a/RAM64.cmp: -------------------------------------------------------------------------------- 1 | | time | in |load |address| out | 2 | | 0+ | 0 | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 0 | 0 | 4 | | 1+ | 0 | 1 | 0 | 0 | 5 | | 2 | 0 | 1 | 0 | 0 | 6 | | 2+ | 1313 | 0 | 0 | 0 | 7 | | 3 | 1313 | 0 | 0 | 0 | 8 | | 3+ | 1313 | 1 | 13 | 0 | 9 | | 4 | 1313 | 1 | 13 | 1313 | 10 | | 4+ | 1313 | 0 | 0 | 0 | 11 | | 5 | 1313 | 0 | 0 | 0 | 12 | | 5+ | 4747 | 0 | 47 | 0 | 13 | | 6 | 4747 | 0 | 47 | 0 | 14 | | 6+ | 4747 | 1 | 47 | 0 | 15 | | 7 | 4747 | 1 | 47 | 4747 | 16 | | 7+ | 4747 | 0 | 47 | 4747 | 17 | | 8 | 4747 | 0 | 47 | 4747 | 18 | | 8 | 4747 | 0 | 13 | 1313 | 19 | | 8+ | 6363 | 0 | 13 | 1313 | 20 | | 9 | 6363 | 0 | 13 | 1313 | 21 | | 9+ | 6363 | 1 | 63 | 0 | 22 | | 10 | 6363 | 1 | 63 | 6363 | 23 | | 10+ | 6363 | 0 | 63 | 6363 | 24 | | 11 | 6363 | 0 | 63 | 6363 | 25 | | 11 | 6363 | 0 | 47 | 4747 | 26 | | 11 | 6363 | 0 | 63 | 6363 | 27 | | 11+ | 6363 | 0 | 40 | 0 | 28 | | 12 | 6363 | 0 | 40 | 0 | 29 | | 12 | 6363 | 0 | 41 | 0 | 30 | | 12 | 6363 | 0 | 42 | 0 | 31 | | 12 | 6363 | 0 | 43 | 0 | 32 | | 12 | 6363 | 0 | 44 | 0 | 33 | | 12 | 6363 | 0 | 45 | 0 | 34 | | 12 | 6363 | 0 | 46 | 0 | 35 | | 12 | 6363 | 0 | 47 | 4747 | 36 | | 12+ | 21845 | 1 | 40 | 0 | 37 | | 13 | 21845 | 1 | 40 | 21845 | 38 | | 13+ | 21845 | 1 | 41 | 0 | 39 | | 14 | 21845 | 1 | 41 | 21845 | 40 | | 14+ | 21845 | 1 | 42 | 0 | 41 | | 15 | 21845 | 1 | 42 | 21845 | 42 | | 15+ | 21845 | 1 | 43 | 0 | 43 | | 16 | 21845 | 1 | 43 | 21845 | 44 | | 16+ | 21845 | 1 | 44 | 0 | 45 | | 17 | 21845 | 1 | 44 | 21845 | 46 | | 17+ | 21845 | 1 | 45 | 0 | 47 | | 18 | 21845 | 1 | 45 | 21845 | 48 | | 18+ | 21845 | 1 | 46 | 0 | 49 | | 19 | 21845 | 1 | 46 | 21845 | 50 | | 19+ | 21845 | 1 | 47 | 4747 | 51 | | 20 | 21845 | 1 | 47 | 21845 | 52 | | 20+ | 21845 | 0 | 40 | 21845 | 53 | | 21 | 21845 | 0 | 40 | 21845 | 54 | | 21 | 21845 | 0 | 41 | 21845 | 55 | | 21 | 21845 | 0 | 42 | 21845 | 56 | | 21 | 21845 | 0 | 43 | 21845 | 57 | | 21 | 21845 | 0 | 44 | 21845 | 58 | | 21 | 21845 | 0 | 45 | 21845 | 59 | | 21 | 21845 | 0 | 46 | 21845 | 60 | | 21 | 21845 | 0 | 47 | 21845 | 61 | | 21+ | -21846 | 1 | 40 | 21845 | 62 | | 22 | -21846 | 1 | 40 | -21846 | 63 | | 22+ | -21846 | 0 | 40 | -21846 | 64 | | 23 | -21846 | 0 | 40 | -21846 | 65 | | 23 | -21846 | 0 | 41 | 21845 | 66 | | 23 | -21846 | 0 | 42 | 21845 | 67 | | 23 | -21846 | 0 | 43 | 21845 | 68 | | 23 | -21846 | 0 | 44 | 21845 | 69 | | 23 | -21846 | 0 | 45 | 21845 | 70 | | 23 | -21846 | 0 | 46 | 21845 | 71 | | 23 | -21846 | 0 | 47 | 21845 | 72 | | 23+ | 21845 | 1 | 40 | -21846 | 73 | | 24 | 21845 | 1 | 40 | 21845 | 74 | | 24+ | -21846 | 1 | 41 | 21845 | 75 | | 25 | -21846 | 1 | 41 | -21846 | 76 | | 25+ | -21846 | 0 | 40 | 21845 | 77 | | 26 | -21846 | 0 | 40 | 21845 | 78 | | 26 | -21846 | 0 | 41 | -21846 | 79 | | 26 | -21846 | 0 | 42 | 21845 | 80 | | 26 | -21846 | 0 | 43 | 21845 | 81 | | 26 | -21846 | 0 | 44 | 21845 | 82 | | 26 | -21846 | 0 | 45 | 21845 | 83 | | 26 | -21846 | 0 | 46 | 21845 | 84 | | 26 | -21846 | 0 | 47 | 21845 | 85 | | 26+ | 21845 | 1 | 41 | -21846 | 86 | | 27 | 21845 | 1 | 41 | 21845 | 87 | | 27+ | -21846 | 1 | 42 | 21845 | 88 | | 28 | -21846 | 1 | 42 | -21846 | 89 | | 28+ | -21846 | 0 | 40 | 21845 | 90 | | 29 | -21846 | 0 | 40 | 21845 | 91 | | 29 | -21846 | 0 | 41 | 21845 | 92 | | 29 | -21846 | 0 | 42 | -21846 | 93 | | 29 | -21846 | 0 | 43 | 21845 | 94 | | 29 | -21846 | 0 | 44 | 21845 | 95 | | 29 | -21846 | 0 | 45 | 21845 | 96 | | 29 | -21846 | 0 | 46 | 21845 | 97 | | 29 | -21846 | 0 | 47 | 21845 | 98 | | 29+ | 21845 | 1 | 42 | -21846 | 99 | | 30 | 21845 | 1 | 42 | 21845 | 100 | | 30+ | -21846 | 1 | 43 | 21845 | 101 | | 31 | -21846 | 1 | 43 | -21846 | 102 | | 31+ | -21846 | 0 | 40 | 21845 | 103 | | 32 | -21846 | 0 | 40 | 21845 | 104 | | 32 | -21846 | 0 | 41 | 21845 | 105 | | 32 | -21846 | 0 | 42 | 21845 | 106 | | 32 | -21846 | 0 | 43 | -21846 | 107 | | 32 | -21846 | 0 | 44 | 21845 | 108 | | 32 | -21846 | 0 | 45 | 21845 | 109 | | 32 | -21846 | 0 | 46 | 21845 | 110 | | 32 | -21846 | 0 | 47 | 21845 | 111 | | 32+ | 21845 | 1 | 43 | -21846 | 112 | | 33 | 21845 | 1 | 43 | 21845 | 113 | | 33+ | -21846 | 1 | 44 | 21845 | 114 | | 34 | -21846 | 1 | 44 | -21846 | 115 | | 34+ | -21846 | 0 | 40 | 21845 | 116 | | 35 | -21846 | 0 | 40 | 21845 | 117 | | 35 | -21846 | 0 | 41 | 21845 | 118 | | 35 | -21846 | 0 | 42 | 21845 | 119 | | 35 | -21846 | 0 | 43 | 21845 | 120 | | 35 | -21846 | 0 | 44 | -21846 | 121 | | 35 | -21846 | 0 | 45 | 21845 | 122 | | 35 | -21846 | 0 | 46 | 21845 | 123 | | 35 | -21846 | 0 | 47 | 21845 | 124 | | 35+ | 21845 | 1 | 44 | -21846 | 125 | | 36 | 21845 | 1 | 44 | 21845 | 126 | | 36+ | -21846 | 1 | 45 | 21845 | 127 | | 37 | -21846 | 1 | 45 | -21846 | 128 | | 37+ | -21846 | 0 | 40 | 21845 | 129 | | 38 | -21846 | 0 | 40 | 21845 | 130 | | 38 | -21846 | 0 | 41 | 21845 | 131 | | 38 | -21846 | 0 | 42 | 21845 | 132 | | 38 | -21846 | 0 | 43 | 21845 | 133 | | 38 | -21846 | 0 | 44 | 21845 | 134 | | 38 | -21846 | 0 | 45 | -21846 | 135 | | 38 | -21846 | 0 | 46 | 21845 | 136 | | 38 | -21846 | 0 | 47 | 21845 | 137 | | 38+ | 21845 | 1 | 45 | -21846 | 138 | | 39 | 21845 | 1 | 45 | 21845 | 139 | | 39+ | -21846 | 1 | 46 | 21845 | 140 | | 40 | -21846 | 1 | 46 | -21846 | 141 | | 40+ | -21846 | 0 | 40 | 21845 | 142 | | 41 | -21846 | 0 | 40 | 21845 | 143 | | 41 | -21846 | 0 | 41 | 21845 | 144 | | 41 | -21846 | 0 | 42 | 21845 | 145 | | 41 | -21846 | 0 | 43 | 21845 | 146 | | 41 | -21846 | 0 | 44 | 21845 | 147 | | 41 | -21846 | 0 | 45 | 21845 | 148 | | 41 | -21846 | 0 | 46 | -21846 | 149 | | 41 | -21846 | 0 | 47 | 21845 | 150 | | 41+ | 21845 | 1 | 46 | -21846 | 151 | | 42 | 21845 | 1 | 46 | 21845 | 152 | | 42+ | -21846 | 1 | 47 | 21845 | 153 | | 43 | -21846 | 1 | 47 | -21846 | 154 | | 43+ | -21846 | 0 | 40 | 21845 | 155 | | 44 | -21846 | 0 | 40 | 21845 | 156 | | 44 | -21846 | 0 | 41 | 21845 | 157 | | 44 | -21846 | 0 | 42 | 21845 | 158 | | 44 | -21846 | 0 | 43 | 21845 | 159 | | 44 | -21846 | 0 | 44 | 21845 | 160 | | 44 | -21846 | 0 | 45 | 21845 | 161 | | 44 | -21846 | 0 | 46 | 21845 | 162 | | 44 | -21846 | 0 | 47 | -21846 | 163 | | 44+ | 21845 | 1 | 47 | -21846 | 164 | | 45 | 21845 | 1 | 47 | 21845 | 165 | | 45+ | 21845 | 0 | 40 | 21845 | 166 | | 46 | 21845 | 0 | 40 | 21845 | 167 | | 46 | 21845 | 0 | 41 | 21845 | 168 | | 46 | 21845 | 0 | 42 | 21845 | 169 | | 46 | 21845 | 0 | 43 | 21845 | 170 | | 46 | 21845 | 0 | 44 | 21845 | 171 | | 46 | 21845 | 0 | 45 | 21845 | 172 | | 46 | 21845 | 0 | 46 | 21845 | 173 | | 46 | 21845 | 0 | 47 | 21845 | 174 | | 46+ | 21845 | 0 | 5 | 0 | 175 | | 47 | 21845 | 0 | 5 | 0 | 176 | | 47 | 21845 | 0 | 13 | 1313 | 177 | | 47 | 21845 | 0 | 21 | 0 | 178 | | 47 | 21845 | 0 | 29 | 0 | 179 | | 47 | 21845 | 0 | 37 | 0 | 180 | | 47 | 21845 | 0 | 45 | 21845 | 181 | | 47 | 21845 | 0 | 53 | 0 | 182 | | 47 | 21845 | 0 | 61 | 0 | 183 | | 47+ | 21845 | 1 | 5 | 0 | 184 | | 48 | 21845 | 1 | 5 | 21845 | 185 | | 48+ | 21845 | 1 | 13 | 1313 | 186 | | 49 | 21845 | 1 | 13 | 21845 | 187 | | 49+ | 21845 | 1 | 21 | 0 | 188 | | 50 | 21845 | 1 | 21 | 21845 | 189 | | 50+ | 21845 | 1 | 29 | 0 | 190 | | 51 | 21845 | 1 | 29 | 21845 | 191 | | 51+ | 21845 | 1 | 37 | 0 | 192 | | 52 | 21845 | 1 | 37 | 21845 | 193 | | 52+ | 21845 | 1 | 45 | 21845 | 194 | | 53 | 21845 | 1 | 45 | 21845 | 195 | | 53+ | 21845 | 1 | 53 | 0 | 196 | | 54 | 21845 | 1 | 53 | 21845 | 197 | | 54+ | 21845 | 1 | 61 | 0 | 198 | | 55 | 21845 | 1 | 61 | 21845 | 199 | | 55+ | 21845 | 0 | 5 | 21845 | 200 | | 56 | 21845 | 0 | 5 | 21845 | 201 | | 56 | 21845 | 0 | 13 | 21845 | 202 | | 56 | 21845 | 0 | 21 | 21845 | 203 | | 56 | 21845 | 0 | 29 | 21845 | 204 | | 56 | 21845 | 0 | 37 | 21845 | 205 | | 56 | 21845 | 0 | 45 | 21845 | 206 | | 56 | 21845 | 0 | 53 | 21845 | 207 | | 56 | 21845 | 0 | 61 | 21845 | 208 | | 56+ | -21846 | 1 | 5 | 21845 | 209 | | 57 | -21846 | 1 | 5 | -21846 | 210 | | 57+ | -21846 | 0 | 5 | -21846 | 211 | | 58 | -21846 | 0 | 5 | -21846 | 212 | | 58 | -21846 | 0 | 13 | 21845 | 213 | | 58 | -21846 | 0 | 21 | 21845 | 214 | | 58 | -21846 | 0 | 29 | 21845 | 215 | | 58 | -21846 | 0 | 37 | 21845 | 216 | | 58 | -21846 | 0 | 45 | 21845 | 217 | | 58 | -21846 | 0 | 53 | 21845 | 218 | | 58 | -21846 | 0 | 61 | 21845 | 219 | | 58+ | 21845 | 1 | 5 | -21846 | 220 | | 59 | 21845 | 1 | 5 | 21845 | 221 | | 59+ | -21846 | 1 | 13 | 21845 | 222 | | 60 | -21846 | 1 | 13 | -21846 | 223 | | 60+ | -21846 | 0 | 5 | 21845 | 224 | | 61 | -21846 | 0 | 5 | 21845 | 225 | | 61 | -21846 | 0 | 13 | -21846 | 226 | | 61 | -21846 | 0 | 21 | 21845 | 227 | | 61 | -21846 | 0 | 29 | 21845 | 228 | | 61 | -21846 | 0 | 37 | 21845 | 229 | | 61 | -21846 | 0 | 45 | 21845 | 230 | | 61 | -21846 | 0 | 53 | 21845 | 231 | | 61 | -21846 | 0 | 61 | 21845 | 232 | | 61+ | 21845 | 1 | 13 | -21846 | 233 | | 62 | 21845 | 1 | 13 | 21845 | 234 | | 62+ | -21846 | 1 | 21 | 21845 | 235 | | 63 | -21846 | 1 | 21 | -21846 | 236 | | 63+ | -21846 | 0 | 5 | 21845 | 237 | | 64 | -21846 | 0 | 5 | 21845 | 238 | | 64 | -21846 | 0 | 13 | 21845 | 239 | | 64 | -21846 | 0 | 21 | -21846 | 240 | | 64 | -21846 | 0 | 29 | 21845 | 241 | | 64 | -21846 | 0 | 37 | 21845 | 242 | | 64 | -21846 | 0 | 45 | 21845 | 243 | | 64 | -21846 | 0 | 53 | 21845 | 244 | | 64 | -21846 | 0 | 61 | 21845 | 245 | | 64+ | 21845 | 1 | 21 | -21846 | 246 | | 65 | 21845 | 1 | 21 | 21845 | 247 | | 65+ | -21846 | 1 | 29 | 21845 | 248 | | 66 | -21846 | 1 | 29 | -21846 | 249 | | 66+ | -21846 | 0 | 5 | 21845 | 250 | | 67 | -21846 | 0 | 5 | 21845 | 251 | | 67 | -21846 | 0 | 13 | 21845 | 252 | | 67 | -21846 | 0 | 21 | 21845 | 253 | | 67 | -21846 | 0 | 29 | -21846 | 254 | | 67 | -21846 | 0 | 37 | 21845 | 255 | | 67 | -21846 | 0 | 45 | 21845 | 256 | | 67 | -21846 | 0 | 53 | 21845 | 257 | | 67 | -21846 | 0 | 61 | 21845 | 258 | | 67+ | 21845 | 1 | 29 | -21846 | 259 | | 68 | 21845 | 1 | 29 | 21845 | 260 | | 68+ | -21846 | 1 | 37 | 21845 | 261 | | 69 | -21846 | 1 | 37 | -21846 | 262 | | 69+ | -21846 | 0 | 5 | 21845 | 263 | | 70 | -21846 | 0 | 5 | 21845 | 264 | | 70 | -21846 | 0 | 13 | 21845 | 265 | | 70 | -21846 | 0 | 21 | 21845 | 266 | | 70 | -21846 | 0 | 29 | 21845 | 267 | | 70 | -21846 | 0 | 37 | -21846 | 268 | | 70 | -21846 | 0 | 45 | 21845 | 269 | | 70 | -21846 | 0 | 53 | 21845 | 270 | | 70 | -21846 | 0 | 61 | 21845 | 271 | | 70+ | 21845 | 1 | 37 | -21846 | 272 | | 71 | 21845 | 1 | 37 | 21845 | 273 | | 71+ | -21846 | 1 | 45 | 21845 | 274 | | 72 | -21846 | 1 | 45 | -21846 | 275 | | 72+ | -21846 | 0 | 5 | 21845 | 276 | | 73 | -21846 | 0 | 5 | 21845 | 277 | | 73 | -21846 | 0 | 13 | 21845 | 278 | | 73 | -21846 | 0 | 21 | 21845 | 279 | | 73 | -21846 | 0 | 29 | 21845 | 280 | | 73 | -21846 | 0 | 37 | 21845 | 281 | | 73 | -21846 | 0 | 45 | -21846 | 282 | | 73 | -21846 | 0 | 53 | 21845 | 283 | | 73 | -21846 | 0 | 61 | 21845 | 284 | | 73+ | 21845 | 1 | 45 | -21846 | 285 | | 74 | 21845 | 1 | 45 | 21845 | 286 | | 74+ | -21846 | 1 | 53 | 21845 | 287 | | 75 | -21846 | 1 | 53 | -21846 | 288 | | 75+ | -21846 | 0 | 5 | 21845 | 289 | | 76 | -21846 | 0 | 5 | 21845 | 290 | | 76 | -21846 | 0 | 13 | 21845 | 291 | | 76 | -21846 | 0 | 21 | 21845 | 292 | | 76 | -21846 | 0 | 29 | 21845 | 293 | | 76 | -21846 | 0 | 37 | 21845 | 294 | | 76 | -21846 | 0 | 45 | 21845 | 295 | | 76 | -21846 | 0 | 53 | -21846 | 296 | | 76 | -21846 | 0 | 61 | 21845 | 297 | | 76+ | 21845 | 1 | 53 | -21846 | 298 | | 77 | 21845 | 1 | 53 | 21845 | 299 | | 77+ | -21846 | 1 | 61 | 21845 | 300 | | 78 | -21846 | 1 | 61 | -21846 | 301 | | 78+ | -21846 | 0 | 5 | 21845 | 302 | | 79 | -21846 | 0 | 5 | 21845 | 303 | | 79 | -21846 | 0 | 13 | 21845 | 304 | | 79 | -21846 | 0 | 21 | 21845 | 305 | | 79 | -21846 | 0 | 29 | 21845 | 306 | | 79 | -21846 | 0 | 37 | 21845 | 307 | | 79 | -21846 | 0 | 45 | 21845 | 308 | | 79 | -21846 | 0 | 53 | 21845 | 309 | | 79 | -21846 | 0 | 61 | -21846 | 310 | | 79+ | 21845 | 1 | 61 | -21846 | 311 | | 80 | 21845 | 1 | 61 | 21845 | 312 | | 80+ | 21845 | 0 | 5 | 21845 | 313 | | 81 | 21845 | 0 | 5 | 21845 | 314 | | 81 | 21845 | 0 | 13 | 21845 | 315 | | 81 | 21845 | 0 | 21 | 21845 | 316 | | 81 | 21845 | 0 | 29 | 21845 | 317 | | 81 | 21845 | 0 | 37 | 21845 | 318 | | 81 | 21845 | 0 | 45 | 21845 | 319 | | 81 | 21845 | 0 | 53 | 21845 | 320 | | 81 | 21845 | 0 | 61 | 21845 | 321 | -------------------------------------------------------------------------------- /project03/a/RAM64.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/03/a/RAM64.hdl 5 | 6 | /** 7 | * Memory of 64 registers, each 16 bit-wide. Out hold 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 after the next time step.) 11 | */ 12 | 13 | CHIP RAM64 { 14 | IN in[16], load, address[6]; 15 | OUT out[16]; 16 | 17 | PARTS: 18 | // Put your code here. 19 | 20 | // Address is 6 bits: xxxyyy 21 | // The xxx refers to the particular RAM8 chip 22 | // The yyy refers to the address on that chip 23 | 24 | // Select the appropriate RAM8 chip with xxx 25 | DMux8Way(in=load, sel=address[0..2], a=loadA, b=loadB, c=loadC, d=loadD, e=loadE, f=loadF, g=loadG, h=loadH); 26 | 27 | // Feed yyy to all of them, and correct chip will get the load bit 28 | RAM8(in=in, load=loadA, address=address[3..5], out=outA); 29 | RAM8(in=in, load=loadB, address=address[3..5], out=outB); 30 | RAM8(in=in, load=loadC, address=address[3..5], out=outC); 31 | RAM8(in=in, load=loadD, address=address[3..5], out=outD); 32 | RAM8(in=in, load=loadE, address=address[3..5], out=outE); 33 | RAM8(in=in, load=loadF, address=address[3..5], out=outF); 34 | RAM8(in=in, load=loadG, address=address[3..5], out=outG); 35 | RAM8(in=in, load=loadH, address=address[3..5], out=outH); 36 | 37 | Mux8Way16(a=outA, b=outB, c=outC, d=outD, e=outE, f=outF, g=outG, h=outH, sel=address[0..2], out=out); 38 | } 39 | -------------------------------------------------------------------------------- /project03/a/RAM8.cmp: -------------------------------------------------------------------------------- 1 | | time | in |load |address| out | 2 | | 0+ | 0 | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 0 | 0 | 4 | | 1+ | 0 | 1 | 0 | 0 | 5 | | 2 | 0 | 1 | 0 | 0 | 6 | | 2+ | 11111 | 0 | 0 | 0 | 7 | | 3 | 11111 | 0 | 0 | 0 | 8 | | 3+ | 11111 | 1 | 1 | 0 | 9 | | 4 | 11111 | 1 | 1 | 11111 | 10 | | 4+ | 11111 | 0 | 0 | 0 | 11 | | 5 | 11111 | 0 | 0 | 0 | 12 | | 5+ | 3333 | 0 | 3 | 0 | 13 | | 6 | 3333 | 0 | 3 | 0 | 14 | | 6+ | 3333 | 1 | 3 | 0 | 15 | | 7 | 3333 | 1 | 3 | 3333 | 16 | | 7+ | 3333 | 0 | 3 | 3333 | 17 | | 8 | 3333 | 0 | 3 | 3333 | 18 | | 8 | 3333 | 0 | 1 | 11111 | 19 | | 8+ | 7777 | 0 | 1 | 11111 | 20 | | 9 | 7777 | 0 | 1 | 11111 | 21 | | 9+ | 7777 | 1 | 7 | 0 | 22 | | 10 | 7777 | 1 | 7 | 7777 | 23 | | 10+ | 7777 | 0 | 7 | 7777 | 24 | | 11 | 7777 | 0 | 7 | 7777 | 25 | | 11 | 7777 | 0 | 3 | 3333 | 26 | | 11 | 7777 | 0 | 7 | 7777 | 27 | | 11+ | 7777 | 0 | 0 | 0 | 28 | | 12 | 7777 | 0 | 0 | 0 | 29 | | 12 | 7777 | 0 | 1 | 11111 | 30 | | 12 | 7777 | 0 | 2 | 0 | 31 | | 12 | 7777 | 0 | 3 | 3333 | 32 | | 12 | 7777 | 0 | 4 | 0 | 33 | | 12 | 7777 | 0 | 5 | 0 | 34 | | 12 | 7777 | 0 | 6 | 0 | 35 | | 12 | 7777 | 0 | 7 | 7777 | 36 | | 12+ | 21845 | 1 | 0 | 0 | 37 | | 13 | 21845 | 1 | 0 | 21845 | 38 | | 13+ | 21845 | 1 | 1 | 11111 | 39 | | 14 | 21845 | 1 | 1 | 21845 | 40 | | 14+ | 21845 | 1 | 2 | 0 | 41 | | 15 | 21845 | 1 | 2 | 21845 | 42 | | 15+ | 21845 | 1 | 3 | 3333 | 43 | | 16 | 21845 | 1 | 3 | 21845 | 44 | | 16+ | 21845 | 1 | 4 | 0 | 45 | | 17 | 21845 | 1 | 4 | 21845 | 46 | | 17+ | 21845 | 1 | 5 | 0 | 47 | | 18 | 21845 | 1 | 5 | 21845 | 48 | | 18+ | 21845 | 1 | 6 | 0 | 49 | | 19 | 21845 | 1 | 6 | 21845 | 50 | | 19+ | 21845 | 1 | 7 | 7777 | 51 | | 20 | 21845 | 1 | 7 | 21845 | 52 | | 20+ | 21845 | 0 | 0 | 21845 | 53 | | 21 | 21845 | 0 | 0 | 21845 | 54 | | 21 | 21845 | 0 | 1 | 21845 | 55 | | 21 | 21845 | 0 | 2 | 21845 | 56 | | 21 | 21845 | 0 | 3 | 21845 | 57 | | 21 | 21845 | 0 | 4 | 21845 | 58 | | 21 | 21845 | 0 | 5 | 21845 | 59 | | 21 | 21845 | 0 | 6 | 21845 | 60 | | 21 | 21845 | 0 | 7 | 21845 | 61 | | 21+ | -21846 | 1 | 0 | 21845 | 62 | | 22 | -21846 | 1 | 0 | -21846 | 63 | | 22+ | -21846 | 0 | 0 | -21846 | 64 | | 23 | -21846 | 0 | 0 | -21846 | 65 | | 23 | -21846 | 0 | 1 | 21845 | 66 | | 23 | -21846 | 0 | 2 | 21845 | 67 | | 23 | -21846 | 0 | 3 | 21845 | 68 | | 23 | -21846 | 0 | 4 | 21845 | 69 | | 23 | -21846 | 0 | 5 | 21845 | 70 | | 23 | -21846 | 0 | 6 | 21845 | 71 | | 23 | -21846 | 0 | 7 | 21845 | 72 | | 23+ | 21845 | 1 | 0 | -21846 | 73 | | 24 | 21845 | 1 | 0 | 21845 | 74 | | 24+ | -21846 | 1 | 1 | 21845 | 75 | | 25 | -21846 | 1 | 1 | -21846 | 76 | | 25+ | -21846 | 0 | 0 | 21845 | 77 | | 26 | -21846 | 0 | 0 | 21845 | 78 | | 26 | -21846 | 0 | 1 | -21846 | 79 | | 26 | -21846 | 0 | 2 | 21845 | 80 | | 26 | -21846 | 0 | 3 | 21845 | 81 | | 26 | -21846 | 0 | 4 | 21845 | 82 | | 26 | -21846 | 0 | 5 | 21845 | 83 | | 26 | -21846 | 0 | 6 | 21845 | 84 | | 26 | -21846 | 0 | 7 | 21845 | 85 | | 26+ | 21845 | 1 | 1 | -21846 | 86 | | 27 | 21845 | 1 | 1 | 21845 | 87 | | 27+ | -21846 | 1 | 2 | 21845 | 88 | | 28 | -21846 | 1 | 2 | -21846 | 89 | | 28+ | -21846 | 0 | 0 | 21845 | 90 | | 29 | -21846 | 0 | 0 | 21845 | 91 | | 29 | -21846 | 0 | 1 | 21845 | 92 | | 29 | -21846 | 0 | 2 | -21846 | 93 | | 29 | -21846 | 0 | 3 | 21845 | 94 | | 29 | -21846 | 0 | 4 | 21845 | 95 | | 29 | -21846 | 0 | 5 | 21845 | 96 | | 29 | -21846 | 0 | 6 | 21845 | 97 | | 29 | -21846 | 0 | 7 | 21845 | 98 | | 29+ | 21845 | 1 | 2 | -21846 | 99 | | 30 | 21845 | 1 | 2 | 21845 | 100 | | 30+ | -21846 | 1 | 3 | 21845 | 101 | | 31 | -21846 | 1 | 3 | -21846 | 102 | | 31+ | -21846 | 0 | 0 | 21845 | 103 | | 32 | -21846 | 0 | 0 | 21845 | 104 | | 32 | -21846 | 0 | 1 | 21845 | 105 | | 32 | -21846 | 0 | 2 | 21845 | 106 | | 32 | -21846 | 0 | 3 | -21846 | 107 | | 32 | -21846 | 0 | 4 | 21845 | 108 | | 32 | -21846 | 0 | 5 | 21845 | 109 | | 32 | -21846 | 0 | 6 | 21845 | 110 | | 32 | -21846 | 0 | 7 | 21845 | 111 | | 32+ | 21845 | 1 | 3 | -21846 | 112 | | 33 | 21845 | 1 | 3 | 21845 | 113 | | 33+ | -21846 | 1 | 4 | 21845 | 114 | | 34 | -21846 | 1 | 4 | -21846 | 115 | | 34+ | -21846 | 0 | 0 | 21845 | 116 | | 35 | -21846 | 0 | 0 | 21845 | 117 | | 35 | -21846 | 0 | 1 | 21845 | 118 | | 35 | -21846 | 0 | 2 | 21845 | 119 | | 35 | -21846 | 0 | 3 | 21845 | 120 | | 35 | -21846 | 0 | 4 | -21846 | 121 | | 35 | -21846 | 0 | 5 | 21845 | 122 | | 35 | -21846 | 0 | 6 | 21845 | 123 | | 35 | -21846 | 0 | 7 | 21845 | 124 | | 35+ | 21845 | 1 | 4 | -21846 | 125 | | 36 | 21845 | 1 | 4 | 21845 | 126 | | 36+ | -21846 | 1 | 5 | 21845 | 127 | | 37 | -21846 | 1 | 5 | -21846 | 128 | | 37+ | -21846 | 0 | 0 | 21845 | 129 | | 38 | -21846 | 0 | 0 | 21845 | 130 | | 38 | -21846 | 0 | 1 | 21845 | 131 | | 38 | -21846 | 0 | 2 | 21845 | 132 | | 38 | -21846 | 0 | 3 | 21845 | 133 | | 38 | -21846 | 0 | 4 | 21845 | 134 | | 38 | -21846 | 0 | 5 | -21846 | 135 | | 38 | -21846 | 0 | 6 | 21845 | 136 | | 38 | -21846 | 0 | 7 | 21845 | 137 | | 38+ | 21845 | 1 | 5 | -21846 | 138 | | 39 | 21845 | 1 | 5 | 21845 | 139 | | 39+ | -21846 | 1 | 6 | 21845 | 140 | | 40 | -21846 | 1 | 6 | -21846 | 141 | | 40+ | -21846 | 0 | 0 | 21845 | 142 | | 41 | -21846 | 0 | 0 | 21845 | 143 | | 41 | -21846 | 0 | 1 | 21845 | 144 | | 41 | -21846 | 0 | 2 | 21845 | 145 | | 41 | -21846 | 0 | 3 | 21845 | 146 | | 41 | -21846 | 0 | 4 | 21845 | 147 | | 41 | -21846 | 0 | 5 | 21845 | 148 | | 41 | -21846 | 0 | 6 | -21846 | 149 | | 41 | -21846 | 0 | 7 | 21845 | 150 | | 41+ | 21845 | 1 | 6 | -21846 | 151 | | 42 | 21845 | 1 | 6 | 21845 | 152 | | 42+ | -21846 | 1 | 7 | 21845 | 153 | | 43 | -21846 | 1 | 7 | -21846 | 154 | | 43+ | -21846 | 0 | 0 | 21845 | 155 | | 44 | -21846 | 0 | 0 | 21845 | 156 | | 44 | -21846 | 0 | 1 | 21845 | 157 | | 44 | -21846 | 0 | 2 | 21845 | 158 | | 44 | -21846 | 0 | 3 | 21845 | 159 | | 44 | -21846 | 0 | 4 | 21845 | 160 | | 44 | -21846 | 0 | 5 | 21845 | 161 | | 44 | -21846 | 0 | 6 | 21845 | 162 | | 44 | -21846 | 0 | 7 | -21846 | 163 | | 44+ | 21845 | 1 | 7 | -21846 | 164 | | 45 | 21845 | 1 | 7 | 21845 | 165 | | 45+ | 21845 | 0 | 0 | 21845 | 166 | | 46 | 21845 | 0 | 0 | 21845 | 167 | | 46 | 21845 | 0 | 1 | 21845 | 168 | | 46 | 21845 | 0 | 2 | 21845 | 169 | | 46 | 21845 | 0 | 3 | 21845 | 170 | | 46 | 21845 | 0 | 4 | 21845 | 171 | | 46 | 21845 | 0 | 5 | 21845 | 172 | | 46 | 21845 | 0 | 6 | 21845 | 173 | | 46 | 21845 | 0 | 7 | 21845 | 174 | -------------------------------------------------------------------------------- /project03/a/RAM8.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/03/a/RAM8.hdl 5 | 6 | /** 7 | * Memory of 8 registers, each 16 bit-wide. Out hold 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 after the next time step.) 11 | */ 12 | 13 | CHIP RAM8 { 14 | IN in[16], load, address[3]; 15 | OUT out[16]; 16 | 17 | PARTS: 18 | // Put your code here. 19 | DMux8Way(in=load, sel=address, a=loadA, b=loadB, c=loadC, d=loadD, e=loadE, f=loadF, g=loadG, h=loadH); 20 | 21 | Register(in=in, load=loadA, out=outA); 22 | Register(in=in, load=loadB, out=outB); 23 | Register(in=in, load=loadC, out=outC); 24 | Register(in=in, load=loadD, out=outD); 25 | Register(in=in, load=loadE, out=outE); 26 | Register(in=in, load=loadF, out=outF); 27 | Register(in=in, load=loadG, out=outG); 28 | Register(in=in, load=loadH, out=outH); 29 | 30 | Mux8Way16(a=outA, b=outB, c=outC, d=outD, e=outE, f=outF, g=outG, h=outH, sel=address, out=out); 31 | } 32 | -------------------------------------------------------------------------------- /project03/a/RAM8.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/03/a/RAM8.tst 5 | 6 | load RAM8.hdl, 7 | output-file RAM8.out, 8 | compare-to RAM8.cmp, 9 | output-list time%S1.4.1 in%D1.6.1 load%B2.1.2 address%D3.1.3 out%D1.6.1; 10 | 11 | set in 0, 12 | set load 0, 13 | set address 0, 14 | tick, 15 | output; 16 | tock, 17 | output; 18 | 19 | set load 1, 20 | tick, 21 | output; 22 | tock, 23 | output; 24 | 25 | set in 11111, 26 | set load 0, 27 | tick, 28 | output; 29 | tock, 30 | output; 31 | 32 | set load 1, 33 | set address 1, 34 | tick, 35 | output; 36 | tock, 37 | output; 38 | 39 | set load 0, 40 | set address 0, 41 | tick, 42 | output; 43 | tock, 44 | output; 45 | 46 | set in 3333, 47 | set address 3, 48 | tick, 49 | output; 50 | tock, 51 | output; 52 | 53 | set load 1, 54 | tick, 55 | output; 56 | tock, 57 | output; 58 | 59 | set load 0, 60 | tick, 61 | output; 62 | tock, 63 | output; 64 | 65 | set address 1, 66 | eval, 67 | output; 68 | 69 | set in 7777, 70 | tick, 71 | output; 72 | tock, 73 | output; 74 | 75 | set load 1, 76 | set address 7, 77 | tick, 78 | output; 79 | tock, 80 | output; 81 | 82 | set load 0, 83 | tick, 84 | output; 85 | tock, 86 | output; 87 | 88 | set address 3, 89 | eval, 90 | output; 91 | 92 | set address 7, 93 | eval, 94 | output; 95 | 96 | set load 0, 97 | set address 0, 98 | tick, 99 | output; 100 | tock, 101 | output; 102 | set address 1, 103 | eval, 104 | output; 105 | set address 2, 106 | eval, 107 | output; 108 | set address 3, 109 | eval, 110 | output; 111 | set address 4, 112 | eval, 113 | output; 114 | set address 5, 115 | eval, 116 | output; 117 | set address 6, 118 | eval, 119 | output; 120 | set address 7, 121 | eval, 122 | output; 123 | 124 | set load 1, 125 | set in %B0101010101010101, 126 | set address 0, 127 | tick, 128 | output; 129 | tock, 130 | output; 131 | set address 1, 132 | tick, 133 | output, 134 | tock, 135 | output; 136 | set address 2, 137 | tick, 138 | output, 139 | tock, 140 | output; 141 | set address 3, 142 | tick, 143 | output, 144 | tock, 145 | output; 146 | set address 4, 147 | tick, 148 | output, 149 | tock, 150 | output; 151 | set address 5, 152 | tick, 153 | output, 154 | tock, 155 | output; 156 | set address 6, 157 | tick, 158 | output, 159 | tock, 160 | output; 161 | set address 7, 162 | tick, 163 | output, 164 | tock, 165 | output; 166 | 167 | set load 0, 168 | set address 0, 169 | tick, 170 | output; 171 | tock, 172 | output; 173 | set address 1, 174 | eval, 175 | output; 176 | set address 2, 177 | eval, 178 | output; 179 | set address 3, 180 | eval, 181 | output; 182 | set address 4, 183 | eval, 184 | output; 185 | set address 5, 186 | eval, 187 | output; 188 | set address 6, 189 | eval, 190 | output; 191 | set address 7, 192 | eval, 193 | output; 194 | 195 | set load 1, 196 | set address 0, 197 | set in %B1010101010101010, 198 | tick, 199 | output; 200 | tock, 201 | output; 202 | 203 | set load 0, 204 | set address 0, 205 | tick, 206 | output; 207 | tock, 208 | output; 209 | set address 1, 210 | eval, 211 | output; 212 | set address 2, 213 | eval, 214 | output; 215 | set address 3, 216 | eval, 217 | output; 218 | set address 4, 219 | eval, 220 | output; 221 | set address 5, 222 | eval, 223 | output; 224 | set address 6, 225 | eval, 226 | output; 227 | set address 7, 228 | eval, 229 | output; 230 | 231 | set load 1, 232 | set address 0, 233 | set in %B0101010101010101, 234 | tick, 235 | output, 236 | tock, 237 | output; 238 | set address 1, 239 | set in %B1010101010101010, 240 | tick, 241 | output; 242 | tock, 243 | output; 244 | 245 | set load 0, 246 | set address 0, 247 | tick, 248 | output; 249 | tock, 250 | output; 251 | set address 1, 252 | eval, 253 | output; 254 | set address 2, 255 | eval, 256 | output; 257 | set address 3, 258 | eval, 259 | output; 260 | set address 4, 261 | eval, 262 | output; 263 | set address 5, 264 | eval, 265 | output; 266 | set address 6, 267 | eval, 268 | output; 269 | set address 7, 270 | eval, 271 | output; 272 | 273 | set load 1, 274 | set address 1, 275 | set in %B0101010101010101, 276 | tick, 277 | output, 278 | tock, 279 | output; 280 | set address 2, 281 | set in %B1010101010101010, 282 | tick, 283 | output; 284 | tock, 285 | output; 286 | 287 | set load 0, 288 | set address 0, 289 | tick, 290 | output; 291 | tock, 292 | output; 293 | set address 1, 294 | eval, 295 | output; 296 | set address 2, 297 | eval, 298 | output; 299 | set address 3, 300 | eval, 301 | output; 302 | set address 4, 303 | eval, 304 | output; 305 | set address 5, 306 | eval, 307 | output; 308 | set address 6, 309 | eval, 310 | output; 311 | set address 7, 312 | eval, 313 | output; 314 | 315 | set load 1, 316 | set address 2, 317 | set in %B0101010101010101, 318 | tick, 319 | output, 320 | tock, 321 | output; 322 | set address 3, 323 | set in %B1010101010101010, 324 | tick, 325 | output; 326 | tock, 327 | output; 328 | 329 | set load 0, 330 | set address 0, 331 | tick, 332 | output; 333 | tock, 334 | output; 335 | set address 1, 336 | eval, 337 | output; 338 | set address 2, 339 | eval, 340 | output; 341 | set address 3, 342 | eval, 343 | output; 344 | set address 4, 345 | eval, 346 | output; 347 | set address 5, 348 | eval, 349 | output; 350 | set address 6, 351 | eval, 352 | output; 353 | set address 7, 354 | eval, 355 | output; 356 | 357 | set load 1, 358 | set address 3, 359 | set in %B0101010101010101, 360 | tick, 361 | output, 362 | tock, 363 | output; 364 | set address 4, 365 | set in %B1010101010101010, 366 | tick, 367 | output; 368 | tock, 369 | output; 370 | 371 | set load 0, 372 | set address 0, 373 | tick, 374 | output; 375 | tock, 376 | output; 377 | set address 1, 378 | eval, 379 | output; 380 | set address 2, 381 | eval, 382 | output; 383 | set address 3, 384 | eval, 385 | output; 386 | set address 4, 387 | eval, 388 | output; 389 | set address 5, 390 | eval, 391 | output; 392 | set address 6, 393 | eval, 394 | output; 395 | set address 7, 396 | eval, 397 | output; 398 | 399 | set load 1, 400 | set address 4, 401 | set in %B0101010101010101, 402 | tick, 403 | output, 404 | tock, 405 | output; 406 | set address 5, 407 | set in %B1010101010101010, 408 | tick, 409 | output; 410 | tock, 411 | output; 412 | 413 | set load 0, 414 | set address 0, 415 | tick, 416 | output; 417 | tock, 418 | output; 419 | set address 1, 420 | eval, 421 | output; 422 | set address 2, 423 | eval, 424 | output; 425 | set address 3, 426 | eval, 427 | output; 428 | set address 4, 429 | eval, 430 | output; 431 | set address 5, 432 | eval, 433 | output; 434 | set address 6, 435 | eval, 436 | output; 437 | set address 7, 438 | eval, 439 | output; 440 | 441 | set load 1, 442 | set address 5, 443 | set in %B0101010101010101, 444 | tick, 445 | output, 446 | tock, 447 | output; 448 | set address 6, 449 | set in %B1010101010101010, 450 | tick, 451 | output; 452 | tock, 453 | output; 454 | 455 | set load 0, 456 | set address 0, 457 | tick, 458 | output; 459 | tock, 460 | output; 461 | set address 1, 462 | eval, 463 | output; 464 | set address 2, 465 | eval, 466 | output; 467 | set address 3, 468 | eval, 469 | output; 470 | set address 4, 471 | eval, 472 | output; 473 | set address 5, 474 | eval, 475 | output; 476 | set address 6, 477 | eval, 478 | output; 479 | set address 7, 480 | eval, 481 | output; 482 | 483 | set load 1, 484 | set address 6, 485 | set in %B0101010101010101, 486 | tick, 487 | output, 488 | tock, 489 | output; 490 | set address 7, 491 | set in %B1010101010101010, 492 | tick, 493 | output; 494 | tock, 495 | output; 496 | 497 | set load 0, 498 | set address 0, 499 | tick, 500 | output; 501 | tock, 502 | output; 503 | set address 1, 504 | eval, 505 | output; 506 | set address 2, 507 | eval, 508 | output; 509 | set address 3, 510 | eval, 511 | output; 512 | set address 4, 513 | eval, 514 | output; 515 | set address 5, 516 | eval, 517 | output; 518 | set address 6, 519 | eval, 520 | output; 521 | set address 7, 522 | eval, 523 | output; 524 | 525 | set load 1, 526 | set address 7, 527 | set in %B0101010101010101, 528 | tick, 529 | output, 530 | tock, 531 | output; 532 | 533 | set load 0, 534 | set address 0, 535 | tick, 536 | output; 537 | tock, 538 | output; 539 | set address 1, 540 | eval, 541 | output; 542 | set address 2, 543 | eval, 544 | output; 545 | set address 3, 546 | eval, 547 | output; 548 | set address 4, 549 | eval, 550 | output; 551 | set address 5, 552 | eval, 553 | output; 554 | set address 6, 555 | eval, 556 | output; 557 | set address 7, 558 | eval, 559 | output; 560 | 561 | -------------------------------------------------------------------------------- /project03/a/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 | -------------------------------------------------------------------------------- /project03/a/Register.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | // Put your code here. 18 | Bit(in=in[0], load=load, out=out[0]); 19 | Bit(in=in[1], load=load, out=out[1]); 20 | Bit(in=in[2], load=load, out=out[2]); 21 | Bit(in=in[3], load=load, out=out[3]); 22 | Bit(in=in[4], load=load, out=out[4]); 23 | Bit(in=in[5], load=load, out=out[5]); 24 | Bit(in=in[6], load=load, out=out[6]); 25 | Bit(in=in[7], load=load, out=out[7]); 26 | Bit(in=in[8], load=load, out=out[8]); 27 | Bit(in=in[9], load=load, out=out[9]); 28 | Bit(in=in[10], load=load, out=out[10]); 29 | Bit(in=in[11], load=load, out=out[11]); 30 | Bit(in=in[12], load=load, out=out[12]); 31 | Bit(in=in[13], load=load, out=out[13]); 32 | Bit(in=in[14], load=load, out=out[14]); 33 | Bit(in=in[15], load=load, out=out[15]); 34 | } 35 | -------------------------------------------------------------------------------- /project03/a/Register.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/03/a/Register.tst 5 | 6 | load Register.hdl, 7 | output-file Register.out, 8 | compare-to Register.cmp, 9 | output-list time%S1.4.1 in%D1.6.1 load%B2.1.2 out%D1.6.1; 10 | 11 | set in 0, 12 | set load 0, 13 | tick, 14 | output; 15 | 16 | tock, 17 | output; 18 | 19 | set in 0, 20 | set load 1, 21 | tick, 22 | output; 23 | 24 | tock, 25 | output; 26 | 27 | set in -32123, 28 | set load 0, 29 | tick, 30 | output; 31 | 32 | tock, 33 | output; 34 | 35 | set in 11111, 36 | set load 0, 37 | tick, 38 | output; 39 | 40 | tock, 41 | output; 42 | 43 | set in -32123, 44 | set load 1, 45 | tick, 46 | output; 47 | 48 | tock, 49 | output; 50 | 51 | set in -32123, 52 | set load 1, 53 | tick, 54 | output; 55 | 56 | tock, 57 | output; 58 | 59 | set in -32123, 60 | set load 0, 61 | tick, 62 | output; 63 | 64 | tock, 65 | output; 66 | 67 | set in 12345, 68 | set load 1, 69 | tick, 70 | output; 71 | 72 | tock, 73 | output; 74 | 75 | set in 0, 76 | set load 0, 77 | tick, 78 | output; 79 | 80 | tock, 81 | output; 82 | 83 | set in 0, 84 | set load 1, 85 | tick, 86 | output; 87 | 88 | tock, 89 | output; 90 | 91 | set in %B0000000000000001, 92 | set load 0, 93 | tick, 94 | output; 95 | 96 | tock, 97 | output; 98 | 99 | set load 1, 100 | tick, 101 | output; 102 | 103 | tock, 104 | output; 105 | 106 | set in %B0000000000000010, 107 | set load 0, 108 | tick, 109 | output; 110 | 111 | tock, 112 | output; 113 | 114 | set load 1, 115 | tick, 116 | output; 117 | 118 | tock, 119 | output; 120 | 121 | set in %B0000000000000100, 122 | set load 0, 123 | tick, 124 | output; 125 | 126 | tock, 127 | output; 128 | 129 | set load 1, 130 | tick, 131 | output; 132 | 133 | tock, 134 | output; 135 | 136 | set in %B0000000000001000, 137 | set load 0, 138 | tick, 139 | output; 140 | 141 | tock, 142 | output; 143 | 144 | set load 1, 145 | tick, 146 | output; 147 | 148 | tock, 149 | output; 150 | 151 | set in %B0000000000010000, 152 | set load 0, 153 | tick, 154 | output; 155 | 156 | tock, 157 | output; 158 | 159 | set load 1, 160 | tick, 161 | output; 162 | 163 | tock, 164 | output; 165 | 166 | set in %B0000000000100000, 167 | set load 0, 168 | tick, 169 | output; 170 | 171 | tock, 172 | output; 173 | 174 | set load 1, 175 | tick, 176 | output; 177 | 178 | tock, 179 | output; 180 | 181 | set in %B0000000001000000, 182 | set load 0, 183 | tick, 184 | output; 185 | 186 | tock, 187 | output; 188 | 189 | set load 1, 190 | tick, 191 | output; 192 | 193 | tock, 194 | output; 195 | 196 | set in %B0000000010000000, 197 | set load 0, 198 | tick, 199 | output; 200 | 201 | tock, 202 | output; 203 | 204 | set load 1, 205 | tick, 206 | output; 207 | 208 | tock, 209 | output; 210 | 211 | set in %B0000000100000000, 212 | set load 0, 213 | tick, 214 | output; 215 | 216 | tock, 217 | output; 218 | 219 | set load 1, 220 | tick, 221 | output; 222 | 223 | tock, 224 | output; 225 | 226 | set in %B0000001000000000, 227 | set load 0, 228 | tick, 229 | output; 230 | 231 | tock, 232 | output; 233 | 234 | set load 1, 235 | tick, 236 | output; 237 | 238 | tock, 239 | output; 240 | 241 | set in %B0000010000000000, 242 | set load 0, 243 | tick, 244 | output; 245 | 246 | tock, 247 | output; 248 | 249 | set load 1, 250 | tick, 251 | output; 252 | 253 | tock, 254 | output; 255 | 256 | set in %B0000100000000000, 257 | set load 0, 258 | tick, 259 | output; 260 | 261 | tock, 262 | output; 263 | 264 | set load 1, 265 | tick, 266 | output; 267 | 268 | tock, 269 | output; 270 | 271 | set in %B0001000000000000, 272 | set load 0, 273 | tick, 274 | output; 275 | 276 | tock, 277 | output; 278 | 279 | set load 1, 280 | tick, 281 | output; 282 | 283 | tock, 284 | output; 285 | 286 | set in %B0010000000000000, 287 | set load 0, 288 | tick, 289 | output; 290 | 291 | tock, 292 | output; 293 | 294 | set load 1, 295 | tick, 296 | output; 297 | 298 | tock, 299 | output; 300 | 301 | set in %B0100000000000000, 302 | set load 0, 303 | tick, 304 | output; 305 | 306 | tock, 307 | output; 308 | 309 | set load 1, 310 | tick, 311 | output; 312 | 313 | tock, 314 | output; 315 | 316 | set in %B1000000000000000, 317 | set load 0, 318 | tick, 319 | output; 320 | 321 | tock, 322 | output; 323 | 324 | set load 1, 325 | tick, 326 | output; 327 | 328 | tock, 329 | output; 330 | 331 | set in %B1111111111111110, 332 | set load 0, 333 | tick, 334 | output; 335 | 336 | tock, 337 | output; 338 | 339 | set load 1, 340 | tick, 341 | output; 342 | 343 | tock, 344 | output; 345 | 346 | set in %B1111111111111101, 347 | set load 0, 348 | tick, 349 | output; 350 | 351 | tock, 352 | output; 353 | 354 | set load 1, 355 | tick, 356 | output; 357 | 358 | tock, 359 | output; 360 | 361 | set in %B1111111111111011, 362 | set load 0, 363 | tick, 364 | output; 365 | 366 | tock, 367 | output; 368 | 369 | set load 1, 370 | tick, 371 | output; 372 | 373 | tock, 374 | output; 375 | 376 | set in %B1111111111110111, 377 | set load 0, 378 | tick, 379 | output; 380 | 381 | tock, 382 | output; 383 | 384 | set load 1, 385 | tick, 386 | output; 387 | 388 | tock, 389 | output; 390 | 391 | set in %B1111111111101111, 392 | set load 0, 393 | tick, 394 | output; 395 | 396 | tock, 397 | output; 398 | 399 | set load 1, 400 | tick, 401 | output; 402 | 403 | tock, 404 | output; 405 | 406 | set in %B1111111111011111, 407 | set load 0, 408 | tick, 409 | output; 410 | 411 | tock, 412 | output; 413 | 414 | set load 1, 415 | tick, 416 | output; 417 | 418 | tock, 419 | output; 420 | 421 | set in %B1111111110111111, 422 | set load 0, 423 | tick, 424 | output; 425 | 426 | tock, 427 | output; 428 | 429 | set load 1, 430 | tick, 431 | output; 432 | 433 | tock, 434 | output; 435 | 436 | set in %B1111111101111111, 437 | set load 0, 438 | tick, 439 | output; 440 | 441 | tock, 442 | output; 443 | 444 | set load 1, 445 | tick, 446 | output; 447 | 448 | tock, 449 | output; 450 | 451 | set in %B1111111011111111, 452 | set load 0, 453 | tick, 454 | output; 455 | 456 | tock, 457 | output; 458 | 459 | set load 1, 460 | tick, 461 | output; 462 | 463 | tock, 464 | output; 465 | 466 | set in %B1111110111111111, 467 | set load 0, 468 | tick, 469 | output; 470 | 471 | tock, 472 | output; 473 | 474 | set load 1, 475 | tick, 476 | output; 477 | 478 | tock, 479 | output; 480 | 481 | set in %B1111101111111111, 482 | set load 0, 483 | tick, 484 | output; 485 | 486 | tock, 487 | output; 488 | 489 | set load 1, 490 | tick, 491 | output; 492 | 493 | tock, 494 | output; 495 | 496 | set in %B1111011111111111, 497 | set load 0, 498 | tick, 499 | output; 500 | 501 | tock, 502 | output; 503 | 504 | set load 1, 505 | tick, 506 | output; 507 | 508 | tock, 509 | output; 510 | 511 | set in %B1110111111111111, 512 | set load 0, 513 | tick, 514 | output; 515 | 516 | tock, 517 | output; 518 | 519 | set load 1, 520 | tick, 521 | output; 522 | 523 | tock, 524 | output; 525 | 526 | set in %B1101111111111111, 527 | set load 0, 528 | tick, 529 | output; 530 | 531 | tock, 532 | output; 533 | 534 | set load 1, 535 | tick, 536 | output; 537 | 538 | tock, 539 | output; 540 | 541 | set in %B1011111111111111, 542 | set load 0, 543 | tick, 544 | output; 545 | 546 | tock, 547 | output; 548 | 549 | set load 1, 550 | tick, 551 | output; 552 | 553 | tock, 554 | output; 555 | 556 | set in %B0111111111111111, 557 | set load 0, 558 | tick, 559 | output; 560 | 561 | tock, 562 | output; 563 | 564 | set load 1, 565 | tick, 566 | output; 567 | 568 | tock, 569 | output; 570 | 571 | -------------------------------------------------------------------------------- /project03/b/RAM16K.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/03/b/RAM16K.hdl 5 | 6 | /** 7 | * Memory of 16K registers, each 16 bit-wide. Out hold 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 after the next time step.) 11 | */ 12 | 13 | CHIP RAM16K { 14 | IN in[16], load, address[14]; 15 | OUT out[16]; 16 | 17 | PARTS: 18 | // Put your code here. 19 | 20 | // Address is 14 bits: xxyyyyyyyyyyyy 21 | // First 2 bits select between 4 RAM4Ks 22 | // Next 12 are passed to that RAM4K and recurse 23 | DMux4Way(in=load, sel=address[0..1], a=loadA, b=loadB, c=loadC, d=loadD); 24 | 25 | RAM4K(in=in, load=loadA, address=address[2..13], out=outA); 26 | RAM4K(in=in, load=loadB, address=address[2..13], out=outB); 27 | RAM4K(in=in, load=loadC, address=address[2..13], out=outC); 28 | RAM4K(in=in, load=loadD, address=address[2..13], out=outD); 29 | 30 | Mux4Way16(a=outA, b=outB, c=outC, d=outD, sel=address[0..1], out=out); 31 | } 32 | -------------------------------------------------------------------------------- /project03/b/RAM4K.cmp: -------------------------------------------------------------------------------- 1 | | time | in |load |address | out | 2 | | 0+ | 0 | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 0 | 0 | 4 | | 1+ | 0 | 1 | 0 | 0 | 5 | | 2 | 0 | 1 | 0 | 0 | 6 | | 2+ | 1111 | 0 | 0 | 0 | 7 | | 3 | 1111 | 0 | 0 | 0 | 8 | | 3+ | 1111 | 1 | 1111 | 0 | 9 | | 4 | 1111 | 1 | 1111 | 1111 | 10 | | 4+ | 1111 | 0 | 0 | 0 | 11 | | 5 | 1111 | 0 | 0 | 0 | 12 | | 5+ | 3513 | 0 | 3513 | 0 | 13 | | 6 | 3513 | 0 | 3513 | 0 | 14 | | 6+ | 3513 | 1 | 3513 | 0 | 15 | | 7 | 3513 | 1 | 3513 | 3513 | 16 | | 7+ | 3513 | 0 | 3513 | 3513 | 17 | | 8 | 3513 | 0 | 3513 | 3513 | 18 | | 8 | 3513 | 0 | 1111 | 1111 | 19 | | 8+ | 4095 | 0 | 1111 | 1111 | 20 | | 9 | 4095 | 0 | 1111 | 1111 | 21 | | 9+ | 4095 | 1 | 4095 | 0 | 22 | | 10 | 4095 | 1 | 4095 | 4095 | 23 | | 10+ | 4095 | 0 | 4095 | 4095 | 24 | | 11 | 4095 | 0 | 4095 | 4095 | 25 | | 11 | 4095 | 0 | 3513 | 3513 | 26 | | 11 | 4095 | 0 | 4095 | 4095 | 27 | | 11+ | 4095 | 0 | 2728 | 0 | 28 | | 12 | 4095 | 0 | 2728 | 0 | 29 | | 12 | 4095 | 0 | 2729 | 0 | 30 | | 12 | 4095 | 0 | 2730 | 0 | 31 | | 12 | 4095 | 0 | 2731 | 0 | 32 | | 12 | 4095 | 0 | 2732 | 0 | 33 | | 12 | 4095 | 0 | 2733 | 0 | 34 | | 12 | 4095 | 0 | 2734 | 0 | 35 | | 12 | 4095 | 0 | 2735 | 0 | 36 | | 12+ | 21845 | 1 | 2728 | 0 | 37 | | 13 | 21845 | 1 | 2728 | 21845 | 38 | | 13+ | 21845 | 1 | 2729 | 0 | 39 | | 14 | 21845 | 1 | 2729 | 21845 | 40 | | 14+ | 21845 | 1 | 2730 | 0 | 41 | | 15 | 21845 | 1 | 2730 | 21845 | 42 | | 15+ | 21845 | 1 | 2731 | 0 | 43 | | 16 | 21845 | 1 | 2731 | 21845 | 44 | | 16+ | 21845 | 1 | 2732 | 0 | 45 | | 17 | 21845 | 1 | 2732 | 21845 | 46 | | 17+ | 21845 | 1 | 2733 | 0 | 47 | | 18 | 21845 | 1 | 2733 | 21845 | 48 | | 18+ | 21845 | 1 | 2734 | 0 | 49 | | 19 | 21845 | 1 | 2734 | 21845 | 50 | | 19+ | 21845 | 1 | 2735 | 0 | 51 | | 20 | 21845 | 1 | 2735 | 21845 | 52 | | 20+ | 21845 | 0 | 2728 | 21845 | 53 | | 21 | 21845 | 0 | 2728 | 21845 | 54 | | 21 | 21845 | 0 | 2729 | 21845 | 55 | | 21 | 21845 | 0 | 2730 | 21845 | 56 | | 21 | 21845 | 0 | 2731 | 21845 | 57 | | 21 | 21845 | 0 | 2732 | 21845 | 58 | | 21 | 21845 | 0 | 2733 | 21845 | 59 | | 21 | 21845 | 0 | 2734 | 21845 | 60 | | 21 | 21845 | 0 | 2735 | 21845 | 61 | | 21+ | -21846 | 1 | 2728 | 21845 | 62 | | 22 | -21846 | 1 | 2728 | -21846 | 63 | | 22+ | -21846 | 0 | 2728 | -21846 | 64 | | 23 | -21846 | 0 | 2728 | -21846 | 65 | | 23 | -21846 | 0 | 2729 | 21845 | 66 | | 23 | -21846 | 0 | 2730 | 21845 | 67 | | 23 | -21846 | 0 | 2731 | 21845 | 68 | | 23 | -21846 | 0 | 2732 | 21845 | 69 | | 23 | -21846 | 0 | 2733 | 21845 | 70 | | 23 | -21846 | 0 | 2734 | 21845 | 71 | | 23 | -21846 | 0 | 2735 | 21845 | 72 | | 23+ | 21845 | 1 | 2728 | -21846 | 73 | | 24 | 21845 | 1 | 2728 | 21845 | 74 | | 24+ | -21846 | 1 | 2729 | 21845 | 75 | | 25 | -21846 | 1 | 2729 | -21846 | 76 | | 25+ | -21846 | 0 | 2728 | 21845 | 77 | | 26 | -21846 | 0 | 2728 | 21845 | 78 | | 26 | -21846 | 0 | 2729 | -21846 | 79 | | 26 | -21846 | 0 | 2730 | 21845 | 80 | | 26 | -21846 | 0 | 2731 | 21845 | 81 | | 26 | -21846 | 0 | 2732 | 21845 | 82 | | 26 | -21846 | 0 | 2733 | 21845 | 83 | | 26 | -21846 | 0 | 2734 | 21845 | 84 | | 26 | -21846 | 0 | 2735 | 21845 | 85 | | 26+ | 21845 | 1 | 2729 | -21846 | 86 | | 27 | 21845 | 1 | 2729 | 21845 | 87 | | 27+ | -21846 | 1 | 2730 | 21845 | 88 | | 28 | -21846 | 1 | 2730 | -21846 | 89 | | 28+ | -21846 | 0 | 2728 | 21845 | 90 | | 29 | -21846 | 0 | 2728 | 21845 | 91 | | 29 | -21846 | 0 | 2729 | 21845 | 92 | | 29 | -21846 | 0 | 2730 | -21846 | 93 | | 29 | -21846 | 0 | 2731 | 21845 | 94 | | 29 | -21846 | 0 | 2732 | 21845 | 95 | | 29 | -21846 | 0 | 2733 | 21845 | 96 | | 29 | -21846 | 0 | 2734 | 21845 | 97 | | 29 | -21846 | 0 | 2735 | 21845 | 98 | | 29+ | 21845 | 1 | 2730 | -21846 | 99 | | 30 | 21845 | 1 | 2730 | 21845 | 100 | | 30+ | -21846 | 1 | 2731 | 21845 | 101 | | 31 | -21846 | 1 | 2731 | -21846 | 102 | | 31+ | -21846 | 0 | 2728 | 21845 | 103 | | 32 | -21846 | 0 | 2728 | 21845 | 104 | | 32 | -21846 | 0 | 2729 | 21845 | 105 | | 32 | -21846 | 0 | 2730 | 21845 | 106 | | 32 | -21846 | 0 | 2731 | -21846 | 107 | | 32 | -21846 | 0 | 2732 | 21845 | 108 | | 32 | -21846 | 0 | 2733 | 21845 | 109 | | 32 | -21846 | 0 | 2734 | 21845 | 110 | | 32 | -21846 | 0 | 2735 | 21845 | 111 | | 32+ | 21845 | 1 | 2731 | -21846 | 112 | | 33 | 21845 | 1 | 2731 | 21845 | 113 | | 33+ | -21846 | 1 | 2732 | 21845 | 114 | | 34 | -21846 | 1 | 2732 | -21846 | 115 | | 34+ | -21846 | 0 | 2728 | 21845 | 116 | | 35 | -21846 | 0 | 2728 | 21845 | 117 | | 35 | -21846 | 0 | 2729 | 21845 | 118 | | 35 | -21846 | 0 | 2730 | 21845 | 119 | | 35 | -21846 | 0 | 2731 | 21845 | 120 | | 35 | -21846 | 0 | 2732 | -21846 | 121 | | 35 | -21846 | 0 | 2733 | 21845 | 122 | | 35 | -21846 | 0 | 2734 | 21845 | 123 | | 35 | -21846 | 0 | 2735 | 21845 | 124 | | 35+ | 21845 | 1 | 2732 | -21846 | 125 | | 36 | 21845 | 1 | 2732 | 21845 | 126 | | 36+ | -21846 | 1 | 2733 | 21845 | 127 | | 37 | -21846 | 1 | 2733 | -21846 | 128 | | 37+ | -21846 | 0 | 2728 | 21845 | 129 | | 38 | -21846 | 0 | 2728 | 21845 | 130 | | 38 | -21846 | 0 | 2729 | 21845 | 131 | | 38 | -21846 | 0 | 2730 | 21845 | 132 | | 38 | -21846 | 0 | 2731 | 21845 | 133 | | 38 | -21846 | 0 | 2732 | 21845 | 134 | | 38 | -21846 | 0 | 2733 | -21846 | 135 | | 38 | -21846 | 0 | 2734 | 21845 | 136 | | 38 | -21846 | 0 | 2735 | 21845 | 137 | | 38+ | 21845 | 1 | 2733 | -21846 | 138 | | 39 | 21845 | 1 | 2733 | 21845 | 139 | | 39+ | -21846 | 1 | 2734 | 21845 | 140 | | 40 | -21846 | 1 | 2734 | -21846 | 141 | | 40+ | -21846 | 0 | 2728 | 21845 | 142 | | 41 | -21846 | 0 | 2728 | 21845 | 143 | | 41 | -21846 | 0 | 2729 | 21845 | 144 | | 41 | -21846 | 0 | 2730 | 21845 | 145 | | 41 | -21846 | 0 | 2731 | 21845 | 146 | | 41 | -21846 | 0 | 2732 | 21845 | 147 | | 41 | -21846 | 0 | 2733 | 21845 | 148 | | 41 | -21846 | 0 | 2734 | -21846 | 149 | | 41 | -21846 | 0 | 2735 | 21845 | 150 | | 41+ | 21845 | 1 | 2734 | -21846 | 151 | | 42 | 21845 | 1 | 2734 | 21845 | 152 | | 42+ | -21846 | 1 | 2735 | 21845 | 153 | | 43 | -21846 | 1 | 2735 | -21846 | 154 | | 43+ | -21846 | 0 | 2728 | 21845 | 155 | | 44 | -21846 | 0 | 2728 | 21845 | 156 | | 44 | -21846 | 0 | 2729 | 21845 | 157 | | 44 | -21846 | 0 | 2730 | 21845 | 158 | | 44 | -21846 | 0 | 2731 | 21845 | 159 | | 44 | -21846 | 0 | 2732 | 21845 | 160 | | 44 | -21846 | 0 | 2733 | 21845 | 161 | | 44 | -21846 | 0 | 2734 | 21845 | 162 | | 44 | -21846 | 0 | 2735 | -21846 | 163 | | 44+ | 21845 | 1 | 2735 | -21846 | 164 | | 45 | 21845 | 1 | 2735 | 21845 | 165 | | 45+ | 21845 | 0 | 2728 | 21845 | 166 | | 46 | 21845 | 0 | 2728 | 21845 | 167 | | 46 | 21845 | 0 | 2729 | 21845 | 168 | | 46 | 21845 | 0 | 2730 | 21845 | 169 | | 46 | 21845 | 0 | 2731 | 21845 | 170 | | 46 | 21845 | 0 | 2732 | 21845 | 171 | | 46 | 21845 | 0 | 2733 | 21845 | 172 | | 46 | 21845 | 0 | 2734 | 21845 | 173 | | 46 | 21845 | 0 | 2735 | 21845 | 174 | | 46+ | 21845 | 0 | 341 | 0 | 175 | | 47 | 21845 | 0 | 341 | 0 | 176 | | 47 | 21845 | 0 | 853 | 0 | 177 | | 47 | 21845 | 0 | 1365 | 0 | 178 | | 47 | 21845 | 0 | 1877 | 0 | 179 | | 47 | 21845 | 0 | 2389 | 0 | 180 | | 47 | 21845 | 0 | 2901 | 0 | 181 | | 47 | 21845 | 0 | 3413 | 0 | 182 | | 47 | 21845 | 0 | 3925 | 0 | 183 | | 47+ | 21845 | 1 | 341 | 0 | 184 | | 48 | 21845 | 1 | 341 | 21845 | 185 | | 48+ | 21845 | 1 | 853 | 0 | 186 | | 49 | 21845 | 1 | 853 | 21845 | 187 | | 49+ | 21845 | 1 | 1365 | 0 | 188 | | 50 | 21845 | 1 | 1365 | 21845 | 189 | | 50+ | 21845 | 1 | 1877 | 0 | 190 | | 51 | 21845 | 1 | 1877 | 21845 | 191 | | 51+ | 21845 | 1 | 2389 | 0 | 192 | | 52 | 21845 | 1 | 2389 | 21845 | 193 | | 52+ | 21845 | 1 | 2901 | 0 | 194 | | 53 | 21845 | 1 | 2901 | 21845 | 195 | | 53+ | 21845 | 1 | 3413 | 0 | 196 | | 54 | 21845 | 1 | 3413 | 21845 | 197 | | 54+ | 21845 | 1 | 3925 | 0 | 198 | | 55 | 21845 | 1 | 3925 | 21845 | 199 | | 55+ | 21845 | 0 | 341 | 21845 | 200 | | 56 | 21845 | 0 | 341 | 21845 | 201 | | 56 | 21845 | 0 | 853 | 21845 | 202 | | 56 | 21845 | 0 | 1365 | 21845 | 203 | | 56 | 21845 | 0 | 1877 | 21845 | 204 | | 56 | 21845 | 0 | 2389 | 21845 | 205 | | 56 | 21845 | 0 | 2901 | 21845 | 206 | | 56 | 21845 | 0 | 3413 | 21845 | 207 | | 56 | 21845 | 0 | 3925 | 21845 | 208 | | 56+ | -21846 | 1 | 341 | 21845 | 209 | | 57 | -21846 | 1 | 341 | -21846 | 210 | | 57+ | -21846 | 0 | 341 | -21846 | 211 | | 58 | -21846 | 0 | 341 | -21846 | 212 | | 58 | -21846 | 0 | 853 | 21845 | 213 | | 58 | -21846 | 0 | 1365 | 21845 | 214 | | 58 | -21846 | 0 | 1877 | 21845 | 215 | | 58 | -21846 | 0 | 2389 | 21845 | 216 | | 58 | -21846 | 0 | 2901 | 21845 | 217 | | 58 | -21846 | 0 | 3413 | 21845 | 218 | | 58 | -21846 | 0 | 3925 | 21845 | 219 | | 58+ | 21845 | 1 | 341 | -21846 | 220 | | 59 | 21845 | 1 | 341 | 21845 | 221 | | 59+ | -21846 | 1 | 853 | 21845 | 222 | | 60 | -21846 | 1 | 853 | -21846 | 223 | | 60+ | -21846 | 0 | 341 | 21845 | 224 | | 61 | -21846 | 0 | 341 | 21845 | 225 | | 61 | -21846 | 0 | 853 | -21846 | 226 | | 61 | -21846 | 0 | 1365 | 21845 | 227 | | 61 | -21846 | 0 | 1877 | 21845 | 228 | | 61 | -21846 | 0 | 2389 | 21845 | 229 | | 61 | -21846 | 0 | 2901 | 21845 | 230 | | 61 | -21846 | 0 | 3413 | 21845 | 231 | | 61 | -21846 | 0 | 3925 | 21845 | 232 | | 61+ | 21845 | 1 | 853 | -21846 | 233 | | 62 | 21845 | 1 | 853 | 21845 | 234 | | 62+ | -21846 | 1 | 1365 | 21845 | 235 | | 63 | -21846 | 1 | 1365 | -21846 | 236 | | 63+ | -21846 | 0 | 341 | 21845 | 237 | | 64 | -21846 | 0 | 341 | 21845 | 238 | | 64 | -21846 | 0 | 853 | 21845 | 239 | | 64 | -21846 | 0 | 1365 | -21846 | 240 | | 64 | -21846 | 0 | 1877 | 21845 | 241 | | 64 | -21846 | 0 | 2389 | 21845 | 242 | | 64 | -21846 | 0 | 2901 | 21845 | 243 | | 64 | -21846 | 0 | 3413 | 21845 | 244 | | 64 | -21846 | 0 | 3925 | 21845 | 245 | | 64+ | 21845 | 1 | 1365 | -21846 | 246 | | 65 | 21845 | 1 | 1365 | 21845 | 247 | | 65+ | -21846 | 1 | 1877 | 21845 | 248 | | 66 | -21846 | 1 | 1877 | -21846 | 249 | | 66+ | -21846 | 0 | 341 | 21845 | 250 | | 67 | -21846 | 0 | 341 | 21845 | 251 | | 67 | -21846 | 0 | 853 | 21845 | 252 | | 67 | -21846 | 0 | 1365 | 21845 | 253 | | 67 | -21846 | 0 | 1877 | -21846 | 254 | | 67 | -21846 | 0 | 2389 | 21845 | 255 | | 67 | -21846 | 0 | 2901 | 21845 | 256 | | 67 | -21846 | 0 | 3413 | 21845 | 257 | | 67 | -21846 | 0 | 3925 | 21845 | 258 | | 67+ | 21845 | 1 | 1877 | -21846 | 259 | | 68 | 21845 | 1 | 1877 | 21845 | 260 | | 68+ | -21846 | 1 | 2389 | 21845 | 261 | | 69 | -21846 | 1 | 2389 | -21846 | 262 | | 69+ | -21846 | 0 | 341 | 21845 | 263 | | 70 | -21846 | 0 | 341 | 21845 | 264 | | 70 | -21846 | 0 | 853 | 21845 | 265 | | 70 | -21846 | 0 | 1365 | 21845 | 266 | | 70 | -21846 | 0 | 1877 | 21845 | 267 | | 70 | -21846 | 0 | 2389 | -21846 | 268 | | 70 | -21846 | 0 | 2901 | 21845 | 269 | | 70 | -21846 | 0 | 3413 | 21845 | 270 | | 70 | -21846 | 0 | 3925 | 21845 | 271 | | 70+ | 21845 | 1 | 2389 | -21846 | 272 | | 71 | 21845 | 1 | 2389 | 21845 | 273 | | 71+ | -21846 | 1 | 2901 | 21845 | 274 | | 72 | -21846 | 1 | 2901 | -21846 | 275 | | 72+ | -21846 | 0 | 341 | 21845 | 276 | | 73 | -21846 | 0 | 341 | 21845 | 277 | | 73 | -21846 | 0 | 853 | 21845 | 278 | | 73 | -21846 | 0 | 1365 | 21845 | 279 | | 73 | -21846 | 0 | 1877 | 21845 | 280 | | 73 | -21846 | 0 | 2389 | 21845 | 281 | | 73 | -21846 | 0 | 2901 | -21846 | 282 | | 73 | -21846 | 0 | 3413 | 21845 | 283 | | 73 | -21846 | 0 | 3925 | 21845 | 284 | | 73+ | 21845 | 1 | 2901 | -21846 | 285 | | 74 | 21845 | 1 | 2901 | 21845 | 286 | | 74+ | -21846 | 1 | 3413 | 21845 | 287 | | 75 | -21846 | 1 | 3413 | -21846 | 288 | | 75+ | -21846 | 0 | 341 | 21845 | 289 | | 76 | -21846 | 0 | 341 | 21845 | 290 | | 76 | -21846 | 0 | 853 | 21845 | 291 | | 76 | -21846 | 0 | 1365 | 21845 | 292 | | 76 | -21846 | 0 | 1877 | 21845 | 293 | | 76 | -21846 | 0 | 2389 | 21845 | 294 | | 76 | -21846 | 0 | 2901 | 21845 | 295 | | 76 | -21846 | 0 | 3413 | -21846 | 296 | | 76 | -21846 | 0 | 3925 | 21845 | 297 | | 76+ | 21845 | 1 | 3413 | -21846 | 298 | | 77 | 21845 | 1 | 3413 | 21845 | 299 | | 77+ | -21846 | 1 | 3925 | 21845 | 300 | | 78 | -21846 | 1 | 3925 | -21846 | 301 | | 78+ | -21846 | 0 | 341 | 21845 | 302 | | 79 | -21846 | 0 | 341 | 21845 | 303 | | 79 | -21846 | 0 | 853 | 21845 | 304 | | 79 | -21846 | 0 | 1365 | 21845 | 305 | | 79 | -21846 | 0 | 1877 | 21845 | 306 | | 79 | -21846 | 0 | 2389 | 21845 | 307 | | 79 | -21846 | 0 | 2901 | 21845 | 308 | | 79 | -21846 | 0 | 3413 | 21845 | 309 | | 79 | -21846 | 0 | 3925 | -21846 | 310 | | 79+ | 21845 | 1 | 3925 | -21846 | 311 | | 80 | 21845 | 1 | 3925 | 21845 | 312 | | 80+ | 21845 | 0 | 341 | 21845 | 313 | | 81 | 21845 | 0 | 341 | 21845 | 314 | | 81 | 21845 | 0 | 853 | 21845 | 315 | | 81 | 21845 | 0 | 1365 | 21845 | 316 | | 81 | 21845 | 0 | 1877 | 21845 | 317 | | 81 | 21845 | 0 | 2389 | 21845 | 318 | | 81 | 21845 | 0 | 2901 | 21845 | 319 | | 81 | 21845 | 0 | 3413 | 21845 | 320 | | 81 | 21845 | 0 | 3925 | 21845 | 321 | -------------------------------------------------------------------------------- /project03/b/RAM4K.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/03/b/RAM4K.hdl 5 | 6 | /** 7 | * Memory of 4K registers, each 16 bit-wide. Out hold 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 after the next time step.) 11 | */ 12 | 13 | CHIP RAM4K { 14 | IN in[16], load, address[12]; 15 | OUT out[16]; 16 | 17 | PARTS: 18 | // Put your code here. 19 | 20 | // Address is 12 bits: xxxyyyyyyyyy 21 | // First 3 bits select the correct RAM512 22 | // Next 9 get passed to that RAM512 and recurse 23 | DMux8Way(in=load, sel=address[0..2], a=loadA, b=loadB, c=loadC, d=loadD, e=loadE, f=loadF, g=loadG, h=loadH); 24 | 25 | // Feed yyyyyyyyy to every RAM512. The load bit will only 26 | // select one. 27 | RAM512(in=in, load=loadA, address=address[3..11], out=outA); 28 | RAM512(in=in, load=loadB, address=address[3..11], out=outB); 29 | RAM512(in=in, load=loadC, address=address[3..11], out=outC); 30 | RAM512(in=in, load=loadD, address=address[3..11], out=outD); 31 | RAM512(in=in, load=loadE, address=address[3..11], out=outE); 32 | RAM512(in=in, load=loadF, address=address[3..11], out=outF); 33 | RAM512(in=in, load=loadG, address=address[3..11], out=outG); 34 | RAM512(in=in, load=loadH, address=address[3..11], out=outH); 35 | 36 | Mux8Way16(a=outA, b=outB, c=outC, d=outD, e=outE, f=outF, g=outG, h=outH, sel=address[0..2], out=out); 37 | } 38 | -------------------------------------------------------------------------------- /project03/b/RAM512.cmp: -------------------------------------------------------------------------------- 1 | | time | in |load |address| out | 2 | | 0+ | 0 | 0 | 0 | 0 | 3 | | 1 | 0 | 0 | 0 | 0 | 4 | | 1+ | 0 | 1 | 0 | 0 | 5 | | 2 | 0 | 1 | 0 | 0 | 6 | | 2+ | 13099 | 0 | 0 | 0 | 7 | | 3 | 13099 | 0 | 0 | 0 | 8 | | 3+ | 13099 | 1 | 130 | 0 | 9 | | 4 | 13099 | 1 | 130 | 13099 | 10 | | 4+ | 13099 | 0 | 0 | 0 | 11 | | 5 | 13099 | 0 | 0 | 0 | 12 | | 5+ | 4729 | 0 | 472 | 0 | 13 | | 6 | 4729 | 0 | 472 | 0 | 14 | | 6+ | 4729 | 1 | 472 | 0 | 15 | | 7 | 4729 | 1 | 472 | 4729 | 16 | | 7+ | 4729 | 0 | 472 | 4729 | 17 | | 8 | 4729 | 0 | 472 | 4729 | 18 | | 8 | 4729 | 0 | 130 | 13099 | 19 | | 8+ | 5119 | 0 | 130 | 13099 | 20 | | 9 | 5119 | 0 | 130 | 13099 | 21 | | 9+ | 5119 | 1 | 511 | 0 | 22 | | 10 | 5119 | 1 | 511 | 5119 | 23 | | 10+ | 5119 | 0 | 511 | 5119 | 24 | | 11 | 5119 | 0 | 511 | 5119 | 25 | | 11 | 5119 | 0 | 472 | 4729 | 26 | | 11 | 5119 | 0 | 511 | 5119 | 27 | | 11+ | 5119 | 0 | 168 | 0 | 28 | | 12 | 5119 | 0 | 168 | 0 | 29 | | 12 | 5119 | 0 | 169 | 0 | 30 | | 12 | 5119 | 0 | 170 | 0 | 31 | | 12 | 5119 | 0 | 171 | 0 | 32 | | 12 | 5119 | 0 | 172 | 0 | 33 | | 12 | 5119 | 0 | 173 | 0 | 34 | | 12 | 5119 | 0 | 174 | 0 | 35 | | 12 | 5119 | 0 | 175 | 0 | 36 | | 12+ | 21845 | 1 | 168 | 0 | 37 | | 13 | 21845 | 1 | 168 | 21845 | 38 | | 13+ | 21845 | 1 | 169 | 0 | 39 | | 14 | 21845 | 1 | 169 | 21845 | 40 | | 14+ | 21845 | 1 | 170 | 0 | 41 | | 15 | 21845 | 1 | 170 | 21845 | 42 | | 15+ | 21845 | 1 | 171 | 0 | 43 | | 16 | 21845 | 1 | 171 | 21845 | 44 | | 16+ | 21845 | 1 | 172 | 0 | 45 | | 17 | 21845 | 1 | 172 | 21845 | 46 | | 17+ | 21845 | 1 | 173 | 0 | 47 | | 18 | 21845 | 1 | 173 | 21845 | 48 | | 18+ | 21845 | 1 | 174 | 0 | 49 | | 19 | 21845 | 1 | 174 | 21845 | 50 | | 19+ | 21845 | 1 | 175 | 0 | 51 | | 20 | 21845 | 1 | 175 | 21845 | 52 | | 20+ | 21845 | 0 | 168 | 21845 | 53 | | 21 | 21845 | 0 | 168 | 21845 | 54 | | 21 | 21845 | 0 | 169 | 21845 | 55 | | 21 | 21845 | 0 | 170 | 21845 | 56 | | 21 | 21845 | 0 | 171 | 21845 | 57 | | 21 | 21845 | 0 | 172 | 21845 | 58 | | 21 | 21845 | 0 | 173 | 21845 | 59 | | 21 | 21845 | 0 | 174 | 21845 | 60 | | 21 | 21845 | 0 | 175 | 21845 | 61 | | 21+ | -21846 | 1 | 168 | 21845 | 62 | | 22 | -21846 | 1 | 168 | -21846 | 63 | | 22+ | -21846 | 0 | 168 | -21846 | 64 | | 23 | -21846 | 0 | 168 | -21846 | 65 | | 23 | -21846 | 0 | 169 | 21845 | 66 | | 23 | -21846 | 0 | 170 | 21845 | 67 | | 23 | -21846 | 0 | 171 | 21845 | 68 | | 23 | -21846 | 0 | 172 | 21845 | 69 | | 23 | -21846 | 0 | 173 | 21845 | 70 | | 23 | -21846 | 0 | 174 | 21845 | 71 | | 23 | -21846 | 0 | 175 | 21845 | 72 | | 23+ | 21845 | 1 | 168 | -21846 | 73 | | 24 | 21845 | 1 | 168 | 21845 | 74 | | 24+ | -21846 | 1 | 169 | 21845 | 75 | | 25 | -21846 | 1 | 169 | -21846 | 76 | | 25+ | -21846 | 0 | 168 | 21845 | 77 | | 26 | -21846 | 0 | 168 | 21845 | 78 | | 26 | -21846 | 0 | 169 | -21846 | 79 | | 26 | -21846 | 0 | 170 | 21845 | 80 | | 26 | -21846 | 0 | 171 | 21845 | 81 | | 26 | -21846 | 0 | 172 | 21845 | 82 | | 26 | -21846 | 0 | 173 | 21845 | 83 | | 26 | -21846 | 0 | 174 | 21845 | 84 | | 26 | -21846 | 0 | 175 | 21845 | 85 | | 26+ | 21845 | 1 | 169 | -21846 | 86 | | 27 | 21845 | 1 | 169 | 21845 | 87 | | 27+ | -21846 | 1 | 170 | 21845 | 88 | | 28 | -21846 | 1 | 170 | -21846 | 89 | | 28+ | -21846 | 0 | 168 | 21845 | 90 | | 29 | -21846 | 0 | 168 | 21845 | 91 | | 29 | -21846 | 0 | 169 | 21845 | 92 | | 29 | -21846 | 0 | 170 | -21846 | 93 | | 29 | -21846 | 0 | 171 | 21845 | 94 | | 29 | -21846 | 0 | 172 | 21845 | 95 | | 29 | -21846 | 0 | 173 | 21845 | 96 | | 29 | -21846 | 0 | 174 | 21845 | 97 | | 29 | -21846 | 0 | 175 | 21845 | 98 | | 29+ | 21845 | 1 | 170 | -21846 | 99 | | 30 | 21845 | 1 | 170 | 21845 | 100 | | 30+ | -21846 | 1 | 171 | 21845 | 101 | | 31 | -21846 | 1 | 171 | -21846 | 102 | | 31+ | -21846 | 0 | 168 | 21845 | 103 | | 32 | -21846 | 0 | 168 | 21845 | 104 | | 32 | -21846 | 0 | 169 | 21845 | 105 | | 32 | -21846 | 0 | 170 | 21845 | 106 | | 32 | -21846 | 0 | 171 | -21846 | 107 | | 32 | -21846 | 0 | 172 | 21845 | 108 | | 32 | -21846 | 0 | 173 | 21845 | 109 | | 32 | -21846 | 0 | 174 | 21845 | 110 | | 32 | -21846 | 0 | 175 | 21845 | 111 | | 32+ | 21845 | 1 | 171 | -21846 | 112 | | 33 | 21845 | 1 | 171 | 21845 | 113 | | 33+ | -21846 | 1 | 172 | 21845 | 114 | | 34 | -21846 | 1 | 172 | -21846 | 115 | | 34+ | -21846 | 0 | 168 | 21845 | 116 | | 35 | -21846 | 0 | 168 | 21845 | 117 | | 35 | -21846 | 0 | 169 | 21845 | 118 | | 35 | -21846 | 0 | 170 | 21845 | 119 | | 35 | -21846 | 0 | 171 | 21845 | 120 | | 35 | -21846 | 0 | 172 | -21846 | 121 | | 35 | -21846 | 0 | 173 | 21845 | 122 | | 35 | -21846 | 0 | 174 | 21845 | 123 | | 35 | -21846 | 0 | 175 | 21845 | 124 | | 35+ | 21845 | 1 | 172 | -21846 | 125 | | 36 | 21845 | 1 | 172 | 21845 | 126 | | 36+ | -21846 | 1 | 173 | 21845 | 127 | | 37 | -21846 | 1 | 173 | -21846 | 128 | | 37+ | -21846 | 0 | 168 | 21845 | 129 | | 38 | -21846 | 0 | 168 | 21845 | 130 | | 38 | -21846 | 0 | 169 | 21845 | 131 | | 38 | -21846 | 0 | 170 | 21845 | 132 | | 38 | -21846 | 0 | 171 | 21845 | 133 | | 38 | -21846 | 0 | 172 | 21845 | 134 | | 38 | -21846 | 0 | 173 | -21846 | 135 | | 38 | -21846 | 0 | 174 | 21845 | 136 | | 38 | -21846 | 0 | 175 | 21845 | 137 | | 38+ | 21845 | 1 | 173 | -21846 | 138 | | 39 | 21845 | 1 | 173 | 21845 | 139 | | 39+ | -21846 | 1 | 174 | 21845 | 140 | | 40 | -21846 | 1 | 174 | -21846 | 141 | | 40+ | -21846 | 0 | 168 | 21845 | 142 | | 41 | -21846 | 0 | 168 | 21845 | 143 | | 41 | -21846 | 0 | 169 | 21845 | 144 | | 41 | -21846 | 0 | 170 | 21845 | 145 | | 41 | -21846 | 0 | 171 | 21845 | 146 | | 41 | -21846 | 0 | 172 | 21845 | 147 | | 41 | -21846 | 0 | 173 | 21845 | 148 | | 41 | -21846 | 0 | 174 | -21846 | 149 | | 41 | -21846 | 0 | 175 | 21845 | 150 | | 41+ | 21845 | 1 | 174 | -21846 | 151 | | 42 | 21845 | 1 | 174 | 21845 | 152 | | 42+ | -21846 | 1 | 175 | 21845 | 153 | | 43 | -21846 | 1 | 175 | -21846 | 154 | | 43+ | -21846 | 0 | 168 | 21845 | 155 | | 44 | -21846 | 0 | 168 | 21845 | 156 | | 44 | -21846 | 0 | 169 | 21845 | 157 | | 44 | -21846 | 0 | 170 | 21845 | 158 | | 44 | -21846 | 0 | 171 | 21845 | 159 | | 44 | -21846 | 0 | 172 | 21845 | 160 | | 44 | -21846 | 0 | 173 | 21845 | 161 | | 44 | -21846 | 0 | 174 | 21845 | 162 | | 44 | -21846 | 0 | 175 | -21846 | 163 | | 44+ | 21845 | 1 | 175 | -21846 | 164 | | 45 | 21845 | 1 | 175 | 21845 | 165 | | 45+ | 21845 | 0 | 168 | 21845 | 166 | | 46 | 21845 | 0 | 168 | 21845 | 167 | | 46 | 21845 | 0 | 169 | 21845 | 168 | | 46 | 21845 | 0 | 170 | 21845 | 169 | | 46 | 21845 | 0 | 171 | 21845 | 170 | | 46 | 21845 | 0 | 172 | 21845 | 171 | | 46 | 21845 | 0 | 173 | 21845 | 172 | | 46 | 21845 | 0 | 174 | 21845 | 173 | | 46 | 21845 | 0 | 175 | 21845 | 174 | | 46+ | 21845 | 0 | 42 | 0 | 175 | | 47 | 21845 | 0 | 42 | 0 | 176 | | 47 | 21845 | 0 | 106 | 0 | 177 | | 47 | 21845 | 0 | 170 | 21845 | 178 | | 47 | 21845 | 0 | 234 | 0 | 179 | | 47 | 21845 | 0 | 298 | 0 | 180 | | 47 | 21845 | 0 | 362 | 0 | 181 | | 47 | 21845 | 0 | 426 | 0 | 182 | | 47 | 21845 | 0 | 490 | 0 | 183 | | 47+ | 21845 | 1 | 42 | 0 | 184 | | 48 | 21845 | 1 | 42 | 21845 | 185 | | 48+ | 21845 | 1 | 106 | 0 | 186 | | 49 | 21845 | 1 | 106 | 21845 | 187 | | 49+ | 21845 | 1 | 170 | 21845 | 188 | | 50 | 21845 | 1 | 170 | 21845 | 189 | | 50+ | 21845 | 1 | 234 | 0 | 190 | | 51 | 21845 | 1 | 234 | 21845 | 191 | | 51+ | 21845 | 1 | 298 | 0 | 192 | | 52 | 21845 | 1 | 298 | 21845 | 193 | | 52+ | 21845 | 1 | 362 | 0 | 194 | | 53 | 21845 | 1 | 362 | 21845 | 195 | | 53+ | 21845 | 1 | 426 | 0 | 196 | | 54 | 21845 | 1 | 426 | 21845 | 197 | | 54+ | 21845 | 1 | 490 | 0 | 198 | | 55 | 21845 | 1 | 490 | 21845 | 199 | | 55+ | 21845 | 0 | 42 | 21845 | 200 | | 56 | 21845 | 0 | 42 | 21845 | 201 | | 56 | 21845 | 0 | 106 | 21845 | 202 | | 56 | 21845 | 0 | 170 | 21845 | 203 | | 56 | 21845 | 0 | 234 | 21845 | 204 | | 56 | 21845 | 0 | 298 | 21845 | 205 | | 56 | 21845 | 0 | 362 | 21845 | 206 | | 56 | 21845 | 0 | 426 | 21845 | 207 | | 56 | 21845 | 0 | 490 | 21845 | 208 | | 56+ | -21846 | 1 | 42 | 21845 | 209 | | 57 | -21846 | 1 | 42 | -21846 | 210 | | 57+ | -21846 | 0 | 42 | -21846 | 211 | | 58 | -21846 | 0 | 42 | -21846 | 212 | | 58 | -21846 | 0 | 106 | 21845 | 213 | | 58 | -21846 | 0 | 170 | 21845 | 214 | | 58 | -21846 | 0 | 234 | 21845 | 215 | | 58 | -21846 | 0 | 298 | 21845 | 216 | | 58 | -21846 | 0 | 362 | 21845 | 217 | | 58 | -21846 | 0 | 426 | 21845 | 218 | | 58 | -21846 | 0 | 490 | 21845 | 219 | | 58+ | 21845 | 1 | 42 | -21846 | 220 | | 59 | 21845 | 1 | 42 | 21845 | 221 | | 59+ | -21846 | 1 | 106 | 21845 | 222 | | 60 | -21846 | 1 | 106 | -21846 | 223 | | 60+ | -21846 | 0 | 42 | 21845 | 224 | | 61 | -21846 | 0 | 42 | 21845 | 225 | | 61 | -21846 | 0 | 106 | -21846 | 226 | | 61 | -21846 | 0 | 170 | 21845 | 227 | | 61 | -21846 | 0 | 234 | 21845 | 228 | | 61 | -21846 | 0 | 298 | 21845 | 229 | | 61 | -21846 | 0 | 362 | 21845 | 230 | | 61 | -21846 | 0 | 426 | 21845 | 231 | | 61 | -21846 | 0 | 490 | 21845 | 232 | | 61+ | 21845 | 1 | 106 | -21846 | 233 | | 62 | 21845 | 1 | 106 | 21845 | 234 | | 62+ | -21846 | 1 | 170 | 21845 | 235 | | 63 | -21846 | 1 | 170 | -21846 | 236 | | 63+ | -21846 | 0 | 42 | 21845 | 237 | | 64 | -21846 | 0 | 42 | 21845 | 238 | | 64 | -21846 | 0 | 106 | 21845 | 239 | | 64 | -21846 | 0 | 170 | -21846 | 240 | | 64 | -21846 | 0 | 234 | 21845 | 241 | | 64 | -21846 | 0 | 298 | 21845 | 242 | | 64 | -21846 | 0 | 362 | 21845 | 243 | | 64 | -21846 | 0 | 426 | 21845 | 244 | | 64 | -21846 | 0 | 490 | 21845 | 245 | | 64+ | 21845 | 1 | 170 | -21846 | 246 | | 65 | 21845 | 1 | 170 | 21845 | 247 | | 65+ | -21846 | 1 | 234 | 21845 | 248 | | 66 | -21846 | 1 | 234 | -21846 | 249 | | 66+ | -21846 | 0 | 42 | 21845 | 250 | | 67 | -21846 | 0 | 42 | 21845 | 251 | | 67 | -21846 | 0 | 106 | 21845 | 252 | | 67 | -21846 | 0 | 170 | 21845 | 253 | | 67 | -21846 | 0 | 234 | -21846 | 254 | | 67 | -21846 | 0 | 298 | 21845 | 255 | | 67 | -21846 | 0 | 362 | 21845 | 256 | | 67 | -21846 | 0 | 426 | 21845 | 257 | | 67 | -21846 | 0 | 490 | 21845 | 258 | | 67+ | 21845 | 1 | 234 | -21846 | 259 | | 68 | 21845 | 1 | 234 | 21845 | 260 | | 68+ | -21846 | 1 | 298 | 21845 | 261 | | 69 | -21846 | 1 | 298 | -21846 | 262 | | 69+ | -21846 | 0 | 42 | 21845 | 263 | | 70 | -21846 | 0 | 42 | 21845 | 264 | | 70 | -21846 | 0 | 106 | 21845 | 265 | | 70 | -21846 | 0 | 170 | 21845 | 266 | | 70 | -21846 | 0 | 234 | 21845 | 267 | | 70 | -21846 | 0 | 298 | -21846 | 268 | | 70 | -21846 | 0 | 362 | 21845 | 269 | | 70 | -21846 | 0 | 426 | 21845 | 270 | | 70 | -21846 | 0 | 490 | 21845 | 271 | | 70+ | 21845 | 1 | 298 | -21846 | 272 | | 71 | 21845 | 1 | 298 | 21845 | 273 | | 71+ | -21846 | 1 | 362 | 21845 | 274 | | 72 | -21846 | 1 | 362 | -21846 | 275 | | 72+ | -21846 | 0 | 42 | 21845 | 276 | | 73 | -21846 | 0 | 42 | 21845 | 277 | | 73 | -21846 | 0 | 106 | 21845 | 278 | | 73 | -21846 | 0 | 170 | 21845 | 279 | | 73 | -21846 | 0 | 234 | 21845 | 280 | | 73 | -21846 | 0 | 298 | 21845 | 281 | | 73 | -21846 | 0 | 362 | -21846 | 282 | | 73 | -21846 | 0 | 426 | 21845 | 283 | | 73 | -21846 | 0 | 490 | 21845 | 284 | | 73+ | 21845 | 1 | 362 | -21846 | 285 | | 74 | 21845 | 1 | 362 | 21845 | 286 | | 74+ | -21846 | 1 | 426 | 21845 | 287 | | 75 | -21846 | 1 | 426 | -21846 | 288 | | 75+ | -21846 | 0 | 42 | 21845 | 289 | | 76 | -21846 | 0 | 42 | 21845 | 290 | | 76 | -21846 | 0 | 106 | 21845 | 291 | | 76 | -21846 | 0 | 170 | 21845 | 292 | | 76 | -21846 | 0 | 234 | 21845 | 293 | | 76 | -21846 | 0 | 298 | 21845 | 294 | | 76 | -21846 | 0 | 362 | 21845 | 295 | | 76 | -21846 | 0 | 426 | -21846 | 296 | | 76 | -21846 | 0 | 490 | 21845 | 297 | | 76+ | 21845 | 1 | 426 | -21846 | 298 | | 77 | 21845 | 1 | 426 | 21845 | 299 | | 77+ | -21846 | 1 | 490 | 21845 | 300 | | 78 | -21846 | 1 | 490 | -21846 | 301 | | 78+ | -21846 | 0 | 42 | 21845 | 302 | | 79 | -21846 | 0 | 42 | 21845 | 303 | | 79 | -21846 | 0 | 106 | 21845 | 304 | | 79 | -21846 | 0 | 170 | 21845 | 305 | | 79 | -21846 | 0 | 234 | 21845 | 306 | | 79 | -21846 | 0 | 298 | 21845 | 307 | | 79 | -21846 | 0 | 362 | 21845 | 308 | | 79 | -21846 | 0 | 426 | 21845 | 309 | | 79 | -21846 | 0 | 490 | -21846 | 310 | | 79+ | 21845 | 1 | 490 | -21846 | 311 | | 80 | 21845 | 1 | 490 | 21845 | 312 | | 80+ | 21845 | 0 | 42 | 21845 | 313 | | 81 | 21845 | 0 | 42 | 21845 | 314 | | 81 | 21845 | 0 | 106 | 21845 | 315 | | 81 | 21845 | 0 | 170 | 21845 | 316 | | 81 | 21845 | 0 | 234 | 21845 | 317 | | 81 | 21845 | 0 | 298 | 21845 | 318 | | 81 | 21845 | 0 | 362 | 21845 | 319 | | 81 | 21845 | 0 | 426 | 21845 | 320 | | 81 | 21845 | 0 | 490 | 21845 | 321 | -------------------------------------------------------------------------------- /project03/b/RAM512.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/03/b/RAM512.hdl 5 | 6 | /** 7 | * Memory of 512 registers, each 16 bit-wide. Out hold 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 after the next time step.) 11 | */ 12 | 13 | CHIP RAM512 { 14 | IN in[16], load, address[9]; 15 | OUT out[16]; 16 | 17 | PARTS: 18 | // Put your code here. 19 | 20 | // Address is 9 bits: xxxyyyyyy 21 | // The first 3 bits select the RAM64 22 | // The last 6 select the address on that chip 23 | DMux8Way(in=load, sel=address[0..2], a=loadA, b=loadB, c=loadC, d=loadD, e=loadE, f=loadF, g=loadG, h=loadH); 24 | 25 | RAM64(in=in, load=loadA, address=address[3..8], out=outA); 26 | RAM64(in=in, load=loadB, address=address[3..8], out=outB); 27 | RAM64(in=in, load=loadC, address=address[3..8], out=outC); 28 | RAM64(in=in, load=loadD, address=address[3..8], out=outD); 29 | RAM64(in=in, load=loadE, address=address[3..8], out=outE); 30 | RAM64(in=in, load=loadF, address=address[3..8], out=outF); 31 | RAM64(in=in, load=loadG, address=address[3..8], out=outG); 32 | RAM64(in=in, load=loadH, address=address[3..8], out=outH); 33 | 34 | Mux8Way16(a=outA, b=outB, c=outC, d=outD, e=outE, f=outF, g=outG, h=outH, sel=address[0..2], out=out); 35 | } 36 | -------------------------------------------------------------------------------- /project04/fill/Fill.asm: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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. When no key is pressed, 9 | // the screen should be cleared. 10 | 11 | // Put your code here. 12 | // if 24576 > 0 fill 13 | // otherwise unfill 14 | 15 | 16 | // define max screen (24576) 17 | @24576 18 | D=A 19 | @MXSCREEN 20 | M=D 21 | 22 | 23 | // define screen pointer (16384) 24 | @SCREEN 25 | D=A 26 | @POINTER 27 | M=D 28 | 29 | 30 | (LOOP) // infinite loop 31 | // If we have keyboard input, jump to FILL 32 | @KBD 33 | D=M 34 | @FILL 35 | D; JGT 36 | 37 | // Otherwise jump to UNFILL 38 | @UNFILL 39 | 0; JMP 40 | 41 | 42 | (UNFILL) 43 | // Do nothing if POINTER == SCREEN 44 | @SCREEN 45 | D=A 46 | @POINTER 47 | D=D-M 48 | @LOOP 49 | D; JEQ 50 | 51 | // Unfill the screen 52 | D=0 53 | @POINTER 54 | A=M 55 | M=D 56 | 57 | // Decrement POINTER 58 | D=1 59 | @POINTER 60 | D=M-D 61 | @POINTER 62 | M=D 63 | 64 | // Jump back to main loop 65 | @LOOP 66 | 0; JMP 67 | 68 | 69 | (FILL) 70 | // Do nothing if the screen is full 71 | @MXSCREEN 72 | D=M 73 | @POINTER 74 | D=D-M 75 | @LOOP 76 | D; JEQ 77 | 78 | 79 | // Fill in the pixel that POINTER points to 80 | //@-1 81 | D=-1 82 | @POINTER 83 | A=M 84 | M=D 85 | 86 | // Iterate pointer by 1 87 | D=1 88 | @POINTER 89 | D=D+M 90 | @POINTER 91 | M=D 92 | 93 | // jump back to main loop 94 | @LOOP 95 | 0; JMP 96 | -------------------------------------------------------------------------------- /project04/fill/Fill.hack: -------------------------------------------------------------------------------- 1 | 0110000000000000 2 | 1110110000010000 3 | 0000000000010000 4 | 1110001100001000 5 | 0100000000000000 6 | 1110110000010000 7 | 0000000000010001 8 | 1110001100001000 9 | 0110000000000000 10 | 1111110000010000 11 | 0000000000011111 12 | 1110001100000001 13 | 0000000000001110 14 | 1110101010000111 15 | 0100000000000000 16 | 1110110000010000 17 | 0000000000010001 18 | 1111010011010000 19 | 0000000000001000 20 | 1110001100000010 21 | 1110101010010000 22 | 0000000000010001 23 | 1111110000100000 24 | 1110001100001000 25 | 1110111111010000 26 | 0000000000010001 27 | 1111000111010000 28 | 0000000000010001 29 | 1110001100001000 30 | 0000000000001000 31 | 1110101010000111 32 | 0000000000010000 33 | 1111110000010000 34 | 0000000000010001 35 | 1111010011010000 36 | 0000000000001000 37 | 1110001100000010 38 | 1110111010010000 39 | 0000000000010001 40 | 1111110000100000 41 | 1110001100001000 42 | 1110111111010000 43 | 0000000000010001 44 | 1111000010010000 45 | 0000000000010001 46 | 1110001100001000 47 | 0000000000001000 48 | 1110101010000111 49 | -------------------------------------------------------------------------------- /project04/fill/Fill.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/04/fill/Fill.tst 5 | 6 | load Fill.hack; 7 | echo "First, make sure that 'No Animation' is selected. Then, select the Keyboard, click on any key and check the screen."; 8 | 9 | repeat { 10 | ticktock; 11 | } 12 | -------------------------------------------------------------------------------- /project04/mult/Iterator.asm: -------------------------------------------------------------------------------- 1 | // Sample program to iterate to 100 2 | 3 | @iterator 4 | M=1 5 | @sum //allocated somewhere 6 | M=0 7 | (LOOP) 8 | @sum 9 | D=M 10 | @100 11 | D=D-A //if count=100 12 | @END 13 | D;JEQ //goto end 14 | @iterator 15 | D=M 16 | @sum 17 | M=D+M //sum=sum+count 18 | @LOOP 19 | 0;JMP 20 | (END) 21 | @END 22 | 0;JMP 23 | -------------------------------------------------------------------------------- /project04/mult/Iterator.hack: -------------------------------------------------------------------------------- 1 | 0000000000010000 2 | 1110111111001000 3 | 0000000000010001 4 | 1110101010001000 5 | 0000000000010001 6 | 1111110000010000 7 | 0000000001100100 8 | 1110010011010000 9 | 0000000000010000 10 | 1110001100000010 11 | 0000000000010000 12 | 1111110000010000 13 | 0000000000010001 14 | 1111000010001000 15 | 0000000000000100 16 | 1110101010000111 17 | 0000000000010000 18 | 1110101010000111 19 | -------------------------------------------------------------------------------- /project04/mult/Mult.asm: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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[3], respectively.) 8 | 9 | // Put your code here. 10 | 11 | 12 | // add first number to itself as many times as second number 13 | @one 14 | M=1 15 | @2 //allocated somewhere 16 | M=0 17 | (LOOP) 18 | @1 19 | D=M // get value of RAM[1] 20 | 21 | @one // load 1 into the ALU and compute RAM[1] - 1 22 | D=D-M //if count=100 23 | 24 | @1 // store value back in RAM[1] 25 | M=D 26 | 27 | @END // jump to end if result == 0 28 | D;JLT //goto end 29 | 30 | @0 // get the value of RAM[0] 31 | D=M 32 | @2 33 | D=D+M // add it to itself 34 | @2 35 | M=D // store it in RAM[5] 36 | 37 | @LOOP 38 | 0;JMP 39 | (END) 40 | @END 41 | 0;JMP 42 | -------------------------------------------------------------------------------- /project04/mult/Mult.cmp: -------------------------------------------------------------------------------- 1 | | RAM[2] | 2 | | 0 | 3 | | 0 | 4 | | 0 | 5 | | 3 | 6 | | 8 | 7 | | 42 | 8 | -------------------------------------------------------------------------------- /project04/mult/Mult.hack: -------------------------------------------------------------------------------- 1 | 0000000000010000 2 | 1110111111001000 3 | 0000000000000010 4 | 1110101010001000 5 | 0000000000000001 6 | 1111110000010000 7 | 0000000000010000 8 | 1111010011010000 9 | 0000000000000001 10 | 1110001100001000 11 | 0000000000010100 12 | 1110001100000100 13 | 0000000000000000 14 | 1111110000010000 15 | 0000000000000010 16 | 1111000010010000 17 | 0000000000000010 18 | 1110001100001000 19 | 0000000000000100 20 | 1110101010000111 21 | 0000000000010100 22 | 1110101010000111 23 | -------------------------------------------------------------------------------- /project04/mult/Mult.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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[2]%D2.6.2; 10 | 11 | set RAM[0] 0, 12 | set RAM[1] 0; 13 | repeat 20 { 14 | ticktock; 15 | } 16 | output; 17 | 18 | set PC 0, 19 | set RAM[0] 1, 20 | set RAM[1] 0; 21 | repeat 50 { 22 | ticktock; 23 | } 24 | output; 25 | 26 | set PC 0, 27 | set RAM[0] 0, 28 | set RAM[1] 2; 29 | repeat 80 { 30 | ticktock; 31 | } 32 | output; 33 | 34 | set PC 0, 35 | set RAM[0] 3, 36 | set RAM[1] 1; 37 | repeat 120 { 38 | ticktock; 39 | } 40 | output; 41 | 42 | set PC 0, 43 | set RAM[0] 2, 44 | set RAM[1] 4; 45 | repeat 150 { 46 | ticktock; 47 | } 48 | output; 49 | 50 | set PC 0, 51 | set RAM[0] 6, 52 | set RAM[1] 7; 53 | repeat 210 { 54 | ticktock; 55 | } 56 | output; 57 | -------------------------------------------------------------------------------- /project05/Add.hack: -------------------------------------------------------------------------------- 1 | 0000000000000010 2 | 1110110000010000 3 | 0000000000000011 4 | 1110000010010000 5 | 0000000000000000 6 | 1110001100001000 7 | -------------------------------------------------------------------------------- /project05/CPU-external.cmp: -------------------------------------------------------------------------------- 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|0000000000011011| 0 | 0| 0 | 2| 23| 41 | |20 | 11111|0000000000011011| 0 | 1| 0 | 27| 24| 42 | |20+ | 11111|1110001100000101| 0 | 1| 0 | 27| 24| 43 | |21 | 11111|1110001100000101| 0 | 1| 0 | 27| 27| 44 | |21+ | 11111|0000000000011101| 0 | 1| 0 | 27| 27| 45 | |22 | 11111|0000000000011101| 0 | 1| 0 | 29| 28| 46 | |22+ | 11111|1110101010000111| 0 | 0| 0 | 29| 28| 47 | |23 | 11111|1110101010000111| 0 | 0| 0 | 29| 29| 48 | |23+ | 11111|1110101010000111| 1 | 0| 0 | 29| 29| 49 | |24 | 11111|1110101010000111| 1 | 0| 0 | 29| 0| 50 | |24+ | 11111|0111111111111111| 0 | 1| 0 | 29| 0| 51 | |25 | 11111|0111111111111111| 0 | 1| 0 |32767| 1| 52 | -------------------------------------------------------------------------------- /project05/CPU-external.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 %B0000000000011011, // @27 71 | tick, output, tock, output; 72 | 73 | set instruction %B1110001100000101, // D;jne 74 | tick, output, tock, output; 75 | 76 | set instruction %B0000000000011101, // @29 77 | tick, output, tock, output; 78 | 79 | set instruction %B1110101010000111, // 0;jmp 80 | tick, output, tock, output; 81 | 82 | set reset 1; 83 | tick, output, tock, output; 84 | 85 | set instruction %B0111111111111111, // @32767 86 | set reset 0; 87 | tick, output, tock, output; 88 | -------------------------------------------------------------------------------- /project05/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|0000000000011011| 0 |*******| 0 | 2| 23| 1 | 41 | |20 | 11111|0000000000011011| 0 |*******| 0 | 27| 24| 1 | 42 | |20+ | 11111|1110001100000101| 0 |*******| 0 | 27| 24| 1 | 43 | |21 | 11111|1110001100000101| 0 |*******| 0 | 27| 27| 1 | 44 | |21+ | 11111|0000000000011101| 0 |*******| 0 | 27| 27| 1 | 45 | |22 | 11111|0000000000011101| 0 |*******| 0 | 29| 28| 1 | 46 | |22+ | 11111|1110101010000111| 0 |*******| 0 | 29| 28| 1 | 47 | |23 | 11111|1110101010000111| 0 |*******| 0 | 29| 29| 1 | 48 | |23+ | 11111|1110101010000111| 1 |*******| 0 | 29| 29| 1 | 49 | |24 | 11111|1110101010000111| 1 |*******| 0 | 29| 0| 1 | 50 | |24+ | 11111|0111111111111111| 0 |*******| 0 | 29| 0| 1 | 51 | |25 | 11111|0111111111111111| 0 |*******| 0 |32767| 1| 1 | 52 | -------------------------------------------------------------------------------- /project05/CPU.hdl: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 4 | // File name: projects/05/CPU.hdl 5 | 6 | /** 7 | * The Central Processing unit (CPU). 8 | * Consists of an ALU and a set of registers, designed to fetch and 9 | * execute instructions written in the Hack machine language. 10 | * 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 unit. If reset=1 then the 24 | * CPU jumps to address 0 (i.e. sets pc=0 in next time unit) rather 25 | * than to the address resulting from executing the current instruction. 26 | */ 27 | 28 | CHIP CPU { 29 | 30 | IN inM[16], // M value input (M = contents of RAM[A]) 31 | instruction[16], // Instruction for execution 32 | reset; // Signals whether to re-start the current 33 | // program (reset=1) or continue executing 34 | // the current program (reset=0). 35 | 36 | OUT outM[16], // M value output 37 | writeM, // Write into M? 38 | addressM[15], // Address in data memory (of M) 39 | pc[15]; // address of next instruction 40 | 41 | PARTS: 42 | // Put your code here. 43 | } 44 | -------------------------------------------------------------------------------- /project05/CPU.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 %B0000000000011011, // @27 71 | tick, output, tock, output; 72 | 73 | set instruction %B1110001100000101, // D;jne 74 | tick, output, tock, output; 75 | 76 | set instruction %B0000000000011101, // @29 77 | tick, output, tock, output; 78 | 79 | set instruction %B1110101010000111, // 0;jmp 80 | tick, output, tock, output; 81 | 82 | set reset 1; 83 | tick, output, tock, output; 84 | 85 | set instruction %B0111111111111111, // @32767 86 | set reset 0; 87 | tick, output, tock, output; 88 | -------------------------------------------------------------------------------- /project05/Computer.hdl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmoylan/Elements-of-Computing-Systems/9f169843689048006b2c9aae358a1f39ea09efe1/project05/Computer.hdl -------------------------------------------------------------------------------- /project05/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 | -------------------------------------------------------------------------------- /project05/ComputerAdd-external.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project05/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 | -------------------------------------------------------------------------------- /project05/ComputerAdd.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project05/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 | -------------------------------------------------------------------------------- /project05/ComputerMax-external.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project05/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 | -------------------------------------------------------------------------------- /project05/ComputerMax.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | -------------------------------------------------------------------------------- /project05/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 | -------------------------------------------------------------------------------- /project05/ComputerRect-external.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | 28 | -------------------------------------------------------------------------------- /project05/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 | -------------------------------------------------------------------------------- /project05/ComputerRect.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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 | 28 | -------------------------------------------------------------------------------- /project05/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 | -------------------------------------------------------------------------------- /project05/Memory.cmp: -------------------------------------------------------------------------------- 1 | | in |load | address | out | 2 | | 0 | 0 | 0 | 0 | 3 | | 0 | 0 | 0 | 0 | 4 | | 0 | 1 | 0 | 0 | 5 | | 0 | 1 | 0 | 0 | 6 | | 4444 | 0 | 0 | 0 | 7 | | 4444 | 0 | 0 | 0 | 8 | | 4444 | 1 | 4444 | 0 | 9 | | 4444 | 1 | 4444 | 4444 | 10 | | 4444 | 0 | 0 | 0 | 11 | | 4444 | 0 | 0 | 0 | 12 | | 13131 | 0 | 13131 | 0 | 13 | | 13131 | 0 | 13131 | 0 | 14 | | 13131 | 1 | 13131 | 0 | 15 | | 13131 | 1 | 13131 | 13131 | 16 | | 13131 | 0 | 13131 | 13131 | 17 | | 13131 | 0 | 13131 | 13131 | 18 | | 13131 | 0 | 4444 | 4444 | 19 | | 16383 | 0 | 4444 | 4444 | 20 | | 16383 | 0 | 4444 | 4444 | 21 | | 16383 | 1 | 16383 | 0 | 22 | | 16383 | 1 | 16383 | 16383 | 23 | | 16383 | 0 | 16383 | 16383 | 24 | | 16383 | 0 | 16383 | 16383 | 25 | | 16383 | 0 | 13131 | 13131 | 26 | | 16383 | 0 | 16383 | 16383 | 27 | | 16383 | 0 | 24576 | 75 | 28 | | -1 | 1 | 20431 | -1 | 29 | | -1 | 1 | 20559 | -1 | 30 | | -1 | 0 | 24576 | 89 | 31 | -------------------------------------------------------------------------------- /project05/Memory.hdl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmoylan/Elements-of-Computing-Systems/9f169843689048006b2c9aae358a1f39ea09efe1/project05/Memory.hdl -------------------------------------------------------------------------------- /project05/Memory.tst: -------------------------------------------------------------------------------- 1 | // This file is part of the materials accompanying the book 2 | // "The Elements of Computing Systems" by Nisan and Schocken, 3 | // MIT Press. Book site: www.idc.ac.il/tecs 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%D2.5.2 out%D1.6.1; 10 | 11 | echo "Before you run this script, select the 'Screen' option from the 'View' menu"; 12 | 13 | set in 0, 14 | set load 0, 15 | set address 0, 16 | tick, 17 | output; 18 | tock, 19 | output; 20 | 21 | set load 1, 22 | tick, 23 | output; 24 | tock, 25 | output; 26 | 27 | set in 4444, 28 | set load 0, 29 | tick, 30 | output; 31 | tock, 32 | output; 33 | 34 | set load 1, 35 | set address 4444, 36 | tick, 37 | output; 38 | tock, 39 | output; 40 | 41 | set load 0, 42 | set address 0, 43 | tick, 44 | output; 45 | tock, 46 | output; 47 | 48 | set in 13131, 49 | set address 13131, 50 | tick, 51 | output; 52 | tock, 53 | output; 54 | 55 | set load 1, 56 | tick, 57 | output; 58 | tock, 59 | output; 60 | 61 | set load 0, 62 | tick, 63 | output; 64 | tock, 65 | output; 66 | 67 | set address 4444, 68 | eval, 69 | output; 70 | 71 | set in 16383, 72 | tick, 73 | output; 74 | tock, 75 | output; 76 | 77 | set load 1, 78 | set address 16383, 79 | tick, 80 | output; 81 | tock, 82 | output; 83 | 84 | set load 0, 85 | tick, 86 | output; 87 | tock, 88 | output; 89 | 90 | set address 13131, 91 | eval, 92 | output; 93 | 94 | set address 16383, 95 | eval, 96 | output; 97 | 98 | set address 24576, 99 | echo "Click the Keyboard icon and hold down the 'K' key (uppercase) until you see the next message (it should appear shortly after that) ...", 100 | // It's important to keep holding the key down since if the system is busy, 101 | // the memory will zero itself before being outputted. 102 | 103 | while out <> 75 { 104 | eval, 105 | } 106 | 107 | clear-echo, 108 | output; 109 | 110 | set load 1, 111 | set in -1, 112 | set address 20431, 113 | tick, 114 | tock, 115 | output, 116 | 117 | set address 20559, 118 | tick, 119 | tock, 120 | output, 121 | 122 | set load 0, 123 | set address 24576, 124 | echo "Make sure that you see two horizontal lines in the middle of the screen. Hold down 'Y' (uppercase) until you see the next message ...", 125 | // It's important to keep holding the key down since if the system is busy, 126 | // the memory will zero itself before being outputted. 127 | 128 | while out <> 89 { 129 | eval, 130 | } 131 | 132 | clear-echo, 133 | output; 134 | -------------------------------------------------------------------------------- /project05/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 | --------------------------------------------------------------------------------