This commit is contained in:
QkoSad
2025-07-16 13:00:37 +03:00
commit 7894b48931
806 changed files with 162532 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And16.hdl
/**
* 16-bit bitwise And:
* for i = 0..15: out[i] = (a[i] and b[i])
*/
CHIP And16 {
IN a[16], b[16];
OUT out[16];
PARTS:
And(a=a[0],b=b[0],out=out[0]);
And(a=a[1],b=b[1],out=out[1]);
And(a=a[2],b=b[2],out=out[2]);
And(a=a[3],b=b[3],out=out[3]);
And(a=a[4],b=b[4],out=out[4]);
And(a=a[5],b=b[5],out=out[5]);
And(a=a[6],b=b[6],out=out[6]);
And(a=a[7],b=b[7],out=out[7]);
And(a=a[8],b=b[8],out=out[8]);
And(a=a[9],b=b[9],out=out[9]);
And(a=a[10],b=b[10],out=out[10]);
And(a=a[11],b=b[11],out=out[11]);
And(a=a[12],b=b[12],out=out[12]);
And(a=a[13],b=b[13],out=out[13]);
And(a=a[14],b=b[14],out=out[14]);
And(a=a[15],b=b[15],out=out[15]);
}
+21
View File
@@ -0,0 +1,21 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux.hdl
/**
* Demultiplexor:
* {a, b} = {in, 0} if sel == 0
* {0, in} if sel == 1
*/
CHIP DMux {
IN in, sel;
OUT a, b;
PARTS:
Not(in=sel,out=notsel);
And(a=in,b=notsel,out=a);
And(a=in,b=sel,out=b);
}
+32
View File
@@ -0,0 +1,32 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux4Way.hdl
/**
* 4-way demultiplexor:
* {a, b, c, d} = {in, 0, 0, 0} if sel == 00
* {0, in, 0, 0} if sel == 01
* {0, 0, in, 0} if sel == 10
* {0, 0, 0, in} if sel == 11
*/
CHIP DMux4Way {
IN in, sel[2];
OUT a, b, c, d;
PARTS:
Not(in=sel[1],out=notsel1);
Not(in=sel[0],out=notsel0);
And(a=notsel1,b=notsel0,out=out1);
And(a=notsel1,b=sel[0],out=out2);
And(a=sel[1],b=notsel0,out=out3);
And(a=sel[1],b=sel[0],out=out4);
And(a=in,b=out1,out=a);
And(a=in,b=out2,out=b);
And(a=in,b=out3,out=c);
And(a=in,b=out4,out=d);
}
+47
View File
@@ -0,0 +1,47 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux8Way.hdl
/**
* 8-way demultiplexor:
* {a, b, c, d, e, f, g, h} = {in, 0, 0, 0, 0, 0, 0, 0} if sel == 000
* {0, in, 0, 0, 0, 0, 0, 0} if sel == 001
* etc.
* {0, 0, 0, 0, 0, 0, 0, in} if sel == 111
*/
CHIP DMux8Way {
IN in, sel[3];
OUT a, b, c, d, e, f, g, h;
PARTS:
Not(in=sel[0],out=notsel0);
Not(in=sel[1],out=notsel1);
Not(in=sel[2],out=notsel2);
And(a=notsel2,b=notsel1,out=out1);
And(a=out1,b=notsel0,out=outA);
And(a=out1,b=sel[0],out=outB);
And(a=notsel2,b=sel[1],out=out2);
And(a=out2,b=notsel0,out=outC);
And(a=out2,b=sel[0],out=outD);
And(a=sel[2],b=notsel1,out=out3);
And(a=out3,b=notsel0,out=outE);
And(a=out3,b=sel[0],out=outF);
And(a=sel[2],b=sel[1],out=out4);
And(a=out4,b=notsel0,out=outG);
And(a=out4,b=sel[0],out=outH);
And(a=in,b=outA,out=a);
And(a=in,b=outB,out=b);
And(a=in,b=outC,out=c);
And(a=in,b=outD,out=d);
And(a=in,b=outE,out=e);
And(a=in,b=outF,out=f);
And(a=in,b=outG,out=g);
And(a=in,b=outH,out=h);
}
+17
View File
@@ -0,0 +1,17 @@
/**
* Multiplexor:
* out = a if sel == 0
* b otherwise
*/
CHIP Mux {
IN a, b, sel;
OUT out;
PARTS:
Not(in=sel,out=notsel);
And(a=a,b=notsel,out=out1);
And(a=b,b=sel,out=out2);
Or(a=out1,b=out2,out=out);
}
+34
View File
@@ -0,0 +1,34 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/11/Mux16.hdl
/**
* 16-bit multiplexor:
* for i = 1..15 out[i] = a[i] if sel == 1
* b[i] if sel == 1
*/
CHIP Mux16 {
IN a[16], b[16], sel;
OUT out[16];
PARTS:
Mux(a=a[0],b=b[0],sel=sel,out=out[0]);
Mux(a=a[1],b=b[1],sel=sel,out=out[1]);
Mux(a=a[2],b=b[2],sel=sel,out=out[2]);
Mux(a=a[3],b=b[3],sel=sel,out=out[3]);
Mux(a=a[4],b=b[4],sel=sel,out=out[4]);
Mux(a=a[5],b=b[5],sel=sel,out=out[5]);
Mux(a=a[6],b=b[6],sel=sel,out=out[6]);
Mux(a=a[7],b=b[7],sel=sel,out=out[7]);
Mux(a=a[8],b=b[8],sel=sel,out=out[8]);
Mux(a=a[9],b=b[9],sel=sel,out=out[9]);
Mux(a=a[10],b=b[10],sel=sel,out=out[10]);
Mux(a=a[11],b=b[11],sel=sel,out=out[11]);
Mux(a=a[12],b=b[12],sel=sel,out=out[12]);
Mux(a=a[13],b=b[13],sel=sel,out=out[13]);
Mux(a=a[14],b=b[14],sel=sel,out=out[14]);
Mux(a=a[15],b=b[15],sel=sel,out=out[15]);
}
+21
View File
@@ -0,0 +1,21 @@
CHIP Mux4Way {
IN a, b, c, d, sel0, sel1;
OUT out;
PARTS:
Not(in=sel0,out=notsel0);
Not(in=sel1,out=notsel1);
And(a=notsel0,b=notsel1,out=outA);
And(a=sel0,b=notsel1,out=outB);
And(a=notsel0,b=sel1,out=outC);
And(a=sel0,b=sel1,out=outD);
And(a=outA,b=a,out=outA1);
And(a=outB,b=b,out=outB1);
And(a=outC,b=c,out=outC1);
And(a=outD,b=d,out=outD1);
Or(a=outA1,b=outB1,out=out1);
Or(a=outC1,b=outD1,out=out2);
Or(a=out1,b=out2,out=out);
}
+38
View File
@@ -0,0 +1,38 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux4Way16.hdl
/**
* 4-way 16-bit multiplexor:
* out = a if sel == 00
* b if sel == 01
* c if sel == 10
* d if sel == 11
*/
CHIP Mux4Way16 {
IN a[16], b[16], c[16], d[16], sel[2];
OUT out[16];
PARTS:
Mux4Way(a=a[0],b=b[0],c=c[0],d=d[0],sel0=sel[0],sel1=sel[1],out=out[0]);
Mux4Way(a=a[1],b=b[1],c=c[1],d=d[1],sel0=sel[0],sel1=sel[1],out=out[1]);
Mux4Way(a=a[2],b=b[2],c=c[2],d=d[2],sel0=sel[0],sel1=sel[1],out=out[2]);
Mux4Way(a=a[3],b=b[3],c=c[3],d=d[3],sel0=sel[0],sel1=sel[1],out=out[3]);
Mux4Way(a=a[4],b=b[4],c=c[4],d=d[4],sel0=sel[0],sel1=sel[1],out=out[4]);
Mux4Way(a=a[5],b=b[5],c=c[5],d=d[5],sel0=sel[0],sel1=sel[1],out=out[5]);
Mux4Way(a=a[6],b=b[6],c=c[6],d=d[6],sel0=sel[0],sel1=sel[1],out=out[6]);
Mux4Way(a=a[7],b=b[7],c=c[7],d=d[7],sel0=sel[0],sel1=sel[1],out=out[7]);
Mux4Way(a=a[8],b=b[8],c=c[8],d=d[8],sel0=sel[0],sel1=sel[1],out=out[8]);
Mux4Way(a=a[9],b=b[9],c=c[9],d=d[9],sel0=sel[0],sel1=sel[1],out=out[9]);
Mux4Way(a=a[10],b=b[10],c=c[10],d=d[10],sel0=sel[0],sel1=sel[1],out=out[10]);
Mux4Way(a=a[11],b=b[11],c=c[11],d=d[11],sel0=sel[0],sel1=sel[1],out=out[11]);
Mux4Way(a=a[12],b=b[12],c=c[12],d=d[12],sel0=sel[0],sel1=sel[1],out=out[12]);
Mux4Way(a=a[13],b=b[13],c=c[13],d=d[13],sel0=sel[0],sel1=sel[1],out=out[13]);
Mux4Way(a=a[14],b=b[14],c=c[14],d=d[14],sel0=sel[0],sel1=sel[1],out=out[14]);
Mux4Way(a=a[15],b=b[15],c=c[15],d=d[15],sel0=sel[0],sel1=sel[1],out=out[15]);
}
+41
View File
@@ -0,0 +1,41 @@
CHIP Mux8Way {
IN a, b, c, d, e, f, g, h, sel0, sel1, sel2;
OUT out;
PARTS:
Not(in=sel0,out=notsel0);
Not(in=sel1,out=notsel1);
Not(in=sel2,out=notsel2);
And(a=notsel0,b=notsel1,out=outA);
And(a=notsel0,b=sel2,out=outC);
And(a=sel0,b=notsel1,out=outE);
And(a=sel0,b=sel1,out=outG);
And(a=outA,b=notsel2,out=outA1);
And(a=outC,b=notsel2,out=outC1);
And(a=outE,b=notsel2,out=outE1);
And(a=outG,b=notsel2,out=outG1);
And(a=outA,b=sel2,out=outB1);
And(a=outG,b=sel2,out=outH1);
And(a=outC,b=sel2,out=outD1);
And(a=outE,b=sel2,out=outF1);
And(a=outA1,b=a,out=outA2);
And(a=outB1,b=b,out=outB2);
And(a=outC1,b=c,out=outC2);
And(a=outD1,b=d,out=outD2);
And(a=outE1,b=e,out=outE2);
And(a=outF1,b=f,out=outF2);
And(a=outG1,b=g,out=outG2);
And(a=outH1,b=h,out=outH2);
Or(a=outA2,b=outB2,out=out1);
Or(a=outC2,b=outD2,out=out2);
Or(a=outE2,b=outF2,out=out4);
Or(a=outG2,b=outH2,out=out5);
Or(a=out4,b=out5,out=out6);
Or(a=out1,b=out2,out=out3);
Or(a=out3,b=out6,out=out);
}
+38
View File
@@ -0,0 +1,38 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux8Way16.hdl
/**
* 8-way 16-bit multiplexor:
* out = a if sel == 000
* b if sel == 001
* etc.
* h if sel == 111
*/
CHIP Mux8Way16 {
IN a[16], b[16], c[16], d[16],
e[16], f[16], g[16], h[16],
sel[3];
OUT out[16];
PARTS:
Mux8Way(a=a[0],b=b[0],c=c[0],d=d[0],e=e[0],f=f[0],g=g[0],h=h[0],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[0]);
Mux8Way(a=a[1],b=b[1],c=c[1],d=d[1],e=e[1],f=f[1],g=g[1],h=h[1],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[1]);
Mux8Way(a=a[2],b=b[2],c=c[2],d=d[2],e=e[2],f=f[2],g=g[2],h=h[2],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[2]);
Mux8Way(a=a[3],b=b[3],c=c[3],d=d[3],e=e[3],f=f[3],g=g[3],h=h[3],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[3]);
Mux8Way(a=a[4],b=b[4],c=c[4],d=d[4],e=e[4],f=f[4],g=g[4],h=h[4],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[4]);
Mux8Way(a=a[5],b=b[5],c=c[5],d=d[5],e=e[5],f=f[5],g=g[5],h=h[5],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[5]);
Mux8Way(a=a[6],b=b[6],c=c[6],d=d[6],e=e[6],f=f[6],g=g[6],h=h[6],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[6]);
Mux8Way(a=a[7],b=b[7],c=c[7],d=d[7],e=e[7],f=f[7],g=g[7],h=h[7],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[7]);
Mux8Way(a=a[8],b=b[8],c=c[8],d=d[8],e=e[8],f=f[8],g=g[8],h=h[8],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[8]);
Mux8Way(a=a[9],b=b[9],c=c[9],d=d[9],e=e[9],f=f[9],g=g[9],h=h[9],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[9]);
Mux8Way(a=a[11],b=b[11],c=c[11],d=d[11],e=e[11],f=f[11],g=g[11],h=h[11],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[11]);
Mux8Way(a=a[12],b=b[12],c=c[12],d=d[12],e=e[12],f=f[12],g=g[12],h=h[12],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[12]);
Mux8Way(a=a[14],b=b[14],c=c[14],d=d[14],e=e[14],f=f[14],g=g[14],h=h[14],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[14]);
Mux8Way(a=a[13],b=b[13],c=c[13],d=d[13],e=e[13],f=f[13],g=g[13],h=h[13],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[13]);
Mux8Way(a=a[15],b=b[15],c=c[15],d=d[15],e=e[15],f=f[15],g=g[15],h=h[15],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[15]);
Mux8Way(a=a[10],b=b[10],c=c[10],d=d[10],e=e[10],f=f[10],g=g[10],h=h[10],sel0=sel[0],sel1=sel[1],sel2=sel[2],out=out[10]);
}
+17
View File
@@ -0,0 +1,17 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Not.hdl
/**
* Not gate:
* out = not in
*/
CHIP Not {
IN in;
OUT out;
PARTS:
Nand(a=in,b=in,out=out);
}
+33
View File
@@ -0,0 +1,33 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Not16.hdl
/**
* 16-bit Not:
* for i=0..15: out[i] = not in[i]
*/
CHIP Not16 {
IN in[16];
OUT out[16];
PARTS:
Not(in=in[0],out=out[0]);
Not(in=in[1],out=out[1]);
Not(in=in[2],out=out[2]);
Not(in=in[3],out=out[3]);
Not(in=in[4],out=out[4]);
Not(in=in[5],out=out[5]);
Not(in=in[6],out=out[6]);
Not(in=in[7],out=out[7]);
Not(in=in[8],out=out[8]);
Not(in=in[9],out=out[9]);
Not(in=in[10],out=out[10]);
Not(in=in[11],out=out[11]);
Not(in=in[12],out=out[12]);
Not(in=in[13],out=out[13]);
Not(in=in[14],out=out[14]);
Not(in=in[15],out=out[15]);
}
+9
View File
@@ -0,0 +1,9 @@
CHIP Or {
IN a, b;
OUT out;
PARTS:
Not(in=a,out=nota);
Not(in=b,out=notb);
Nand(a=nota,b=notb,out=out);
}
+33
View File
@@ -0,0 +1,33 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/11/Or16.hdl
/**
* 16-bit bitwise Or:
* for i = 1..15 out[i] = (a[i] or b[i])
*/
CHIP Or16 {
IN a[16], b[16];
OUT out[16];
PARTS:
Or(a=a[0],b=b[0],out=out[0]);
Or(a=a[1],b=b[1],out=out[1]);
Or(a=a[2],b=b[2],out=out[2]);
Or(a=a[3],b=b[3],out=out[3]);
Or(a=a[4],b=b[4],out=out[4]);
Or(a=a[5],b=b[5],out=out[5]);
Or(a=a[6],b=b[6],out=out[6]);
Or(a=a[7],b=b[7],out=out[7]);
Or(a=a[8],b=b[8],out=out[8]);
Or(a=a[9],b=b[9],out=out[9]);
Or(a=a[10],b=b[10],out=out[10]);
Or(a=a[11],b=b[11],out=out[11]);
Or(a=a[12],b=b[12],out=out[12]);
Or(a=a[13],b=b[13],out=out[13]);
Or(a=a[14],b=b[14],out=out[14]);
Or(a=a[15],b=b[15],out=out[15]);
}
+25
View File
@@ -0,0 +1,25 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Or8Way.hdl
/**
* 8-way Or:
* out = (in[0] or in[1] or ... or in[7])
*/
CHIP Or8Way {
IN in[8];
OUT out;
PARTS:
Or(a=in[0],b=in[1],out=out1);
Or(a=out1,b=in[2],out=out2);
Or(a=out2,b=in[3],out=out3);
Or(a=out3,b=in[4],out=out4);
Or(a=out4,b=in[5],out=out5);
Or(a=out5,b=in[6],out=out6);
Or(a=out6,b=in[7],out=out);
}