Initial Commit with everything done

This commit is contained in:
2021-04-13 00:07:23 +03:00
commit 20cf599d89
33 changed files with 1019 additions and 0 deletions
+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/03/a/Bit.hdl
/**
* 1-bit register:
* If load[t] == 1 then out[t+1] = in[t]
* else out does not change (out[t+1] = out[t])
*/
CHIP Bit {
IN in, load;
OUT out;
PARTS:
// Put your code here:
Not(in=load,out=negLoad);
And(a=in,b=load,out=out1);
And(a=b,b=negLoad,out=out2);
Xor(a=out1,b=out2,out=a);
DFF(in=a,out=b,out=out);
}
+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/03/a/PC.hdl
/**
* A 16-bit counter with load and reset control bits.
* if (reset[t] == 1) out[t+1] = 0
* else if (load[t] == 1) out[t+1] = in[t]
* else if (inc[t] == 1) out[t+1] = out[t] + 1 (integer addition)
* else out[t+1] = out[t]
*/
CHIP PC {
IN in[16],load,inc,reset;
OUT out[16];
PARTS:
// Put your code here:
Or(a=reset,b=load,out=load1);
Or(a=load1,b=inc,out=trueLoad);
Inc16(in=b,out=incIn);
And16(a=incIn,b[0]=inc,b[1]=inc,b[2]=inc,b[3]=inc,b[4]=inc,b[5]=inc,b[6]=inc,b[7]=inc,b[8]=inc,b[9]=inc,b[10]=inc,b[11]=inc,b[12]=inc,b[13]=inc,b[14]=inc,b[15]=inc,out=in1);
Not(in=reset,out=negReset);
And16(a=in,b[0]=negReset,b[1]=negReset,b[2]=negReset,b[3]=negReset,b[4]=negReset,b[5]=negReset,b[6]=negReset,b[7]=negReset,b[8]=negReset,b[9]=negReset,b[10]=negReset,b[11]=negReset,b[12]=negReset,b[13]=negReset,b[14]=negReset,b[15]=negReset,out=in2);
Not(in=load,out=negLoad);
And(a=negReset,b=negLoad,out=out1);
And(a=inc,b=out1,out=sel);
Mux16(a=in2,b=in1,sel=sel,out=trueIn);
Register(in=trueIn,load=trueLoad,out=out,out=b);
}
+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/03/b/RAM16K.hdl
/**
* Memory of 16K registers, each 16 bit-wide. Out holds the value
* stored at the memory location specified by address. If load==1, then
* the in value is loaded into the memory location specified by address
* (the loaded value will be emitted to out from the next time step onward).
*/
CHIP RAM16K {
IN in[16], load, address[14];
OUT out[16];
PARTS:
// Put your code here:
DMux4Way(in=load,sel[0]=address[0],sel[1]=address[1],a=a,b=b,c=c,d=d);
RAM4K(in=in,load=a,address[0]=address[2],address[1]=address[3],address[2]=address[4],address[3]=address[5],address[4]=address[6],address[5]=address[7],address[6]=address[8],address[7]=address[9],address[8]=address[10],address[9]=address[11],address[10]=address[12],address[11]=address[13],out=out1);
RAM4K(in=in,load=b,address[0]=address[2],address[1]=address[3],address[2]=address[4],address[3]=address[5],address[4]=address[6],address[5]=address[7],address[6]=address[8],address[7]=address[9],address[8]=address[10],address[9]=address[11],address[10]=address[12],address[11]=address[13],out=out2);
RAM4K(in=in,load=c,address[0]=address[2],address[1]=address[3],address[2]=address[4],address[3]=address[5],address[4]=address[6],address[5]=address[7],address[6]=address[8],address[7]=address[9],address[8]=address[10],address[9]=address[11],address[10]=address[12],address[11]=address[13],out=out3);
RAM4K(in=in,load=d,address[0]=address[2],address[1]=address[3],address[2]=address[4],address[3]=address[5],address[4]=address[6],address[5]=address[7],address[6]=address[8],address[7]=address[9],address[8]=address[10],address[9]=address[11],address[10]=address[12],address[11]=address[13],out=out4);
Mux8Way16(a=out1,b=out2,c=out3,d=out4,sel[0]=address[0],sel[1]=address[1],out=out);
}
+29
View File
@@ -0,0 +1,29 @@
// 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/03/b/RAM4K.hdl
/**
* Memory of 4K registers, each 16 bit-wide. Out holds the value
* stored at the memory location specified by address. If load==1, then
* the in value is loaded into the memory location specified by address
* (the loaded value will be emitted to out from the next time step onward).
*/
CHIP RAM4K {
IN in[16], load, address[12];
OUT out[16];
PARTS:
// Put your code here:
DMux8Way(in=load,sel[0]=address[0],sel[1]=address[1],sel[2]=address[2],a=a,b=b,c=c,d=d,e=e,f=f,g=g,h=h);
RAM512(in=in,load=a,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],address[6]=address[9],address[7]=address[10],address[8]=address[11],out=out1);
RAM512(in=in,load=b,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],address[6]=address[9],address[7]=address[10],address[8]=address[11],out=out2);
RAM512(in=in,load=c,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],address[6]=address[9],address[7]=address[10],address[8]=address[11],out=out3);
RAM512(in=in,load=d,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],address[6]=address[9],address[7]=address[10],address[8]=address[11],out=out4);
RAM512(in=in,load=e,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],address[6]=address[9],address[7]=address[10],address[8]=address[11],out=out5);
RAM512(in=in,load=f,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],address[6]=address[9],address[7]=address[10],address[8]=address[11],out=out6);
RAM512(in=in,load=g,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],address[6]=address[9],address[7]=address[10],address[8]=address[11],out=out7);
RAM512(in=in,load=h,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],address[6]=address[9],address[7]=address[10],address[8]=address[11],out=out8);
Mux8Way16(a=out1,b=out2,c=out3,d=out4,e=out5,f=out6,g=out7,h=out8,sel[0]=address[0],sel[1]=address[1],sel[2]=address[2],out=out);
}
+29
View File
@@ -0,0 +1,29 @@
// This file is part of the materials accompanying the book
// "The Elements of Computing Systems" by Nisan and Schocken,
// MIT Press. Book site: www.idc.ac.il/tecs
// File name: projects/03/b/RAM512.hdl
/**
* Memory of 512 registers, each 16 bit-wide. Out holds the value
* stored at the memory location specified by address. If load==1, then
* the in value is loaded into the memory location specified by address
* (the loaded value will be emitted to out from the next time step onward).
*/
CHIP RAM512 {
IN in[16], load, address[9];
OUT out[16];
PARTS:
// Put your code here:
DMux8Way(in=load,sel[0]=address[0],sel[1]=address[1],sel[2]=address[2],a=a,b=b,c=c,d=d,e=e,f=f,g=g,h=h);
RAM64(in=in,load=a,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],out=out1);
RAM64(in=in,load=b,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],out=out2);
RAM64(in=in,load=c,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],out=out3);
RAM64(in=in,load=d,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],out=out4);
RAM64(in=in,load=e,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],out=out5);
RAM64(in=in,load=f,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],out=out6);
RAM64(in=in,load=g,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],out=out7);
RAM64(in=in,load=h,address[0]=address[3],address[1]=address[4],address[2]=address[5],address[3]=address[6],address[4]=address[7],address[5]=address[8],out=out8);
Mux8Way16(a=out1,b=out2,c=out3,d=out4,e=out5,f=out6,g=out7,h=out8,sel[0]=address[0],sel[1]=address[1],sel[2]=address[2],out=out);
}
+31
View File
@@ -0,0 +1,31 @@
// 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/03/a/RAM64.hdl
/**
* Memory of 64 registers, each 16 bit-wide. Out holds the value
* stored at the memory location specified by address. If load==1, then
* the in value is loaded into the memory location specified by address
* (the loaded value will be emitted to out from the next time step onward).
*/
CHIP RAM64 {
IN in[16], load, address[6];
OUT out[16];
PARTS:
// Put your code here:
DMux8Way(in=load,sel[0]=address[0],sel[1]=address[1],sel[2]=address[2],a=a,b=b,c=c,d=d,e=e,f=f,g=g,h=h);
RAM8(in=in,load=a,address[0]=address[3],address[1]=address[4],address[2]=address[5],out=out1);
RAM8(in=in,load=b,address[0]=address[3],address[1]=address[4],address[2]=address[5],out=out2);
RAM8(in=in,load=c,address[0]=address[3],address[1]=address[4],address[2]=address[5],out=out3);
RAM8(in=in,load=d,address[0]=address[3],address[1]=address[4],address[2]=address[5],out=out4);
RAM8(in=in,load=e,address[0]=address[3],address[1]=address[4],address[2]=address[5],out=out5);
RAM8(in=in,load=f,address[0]=address[3],address[1]=address[4],address[2]=address[5],out=out6);
RAM8(in=in,load=g,address[0]=address[3],address[1]=address[4],address[2]=address[5],out=out7);
RAM8(in=in,load=h,address[0]=address[3],address[1]=address[4],address[2]=address[5],out=out8);
Mux8Way16(a=out1,b=out2,c=out3,d=out4,e=out5,f=out6,g=out7,h=out8,sel[0]=address[0],sel[1]=address[1],sel[2]=address[2],out=out);
}
+29
View File
@@ -0,0 +1,29 @@
// 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/03/a/RAM8.hdl
/**
* Memory of 8 registers, each 16 bit-wide. Out holds the value
* stored at the memory location specified by address. If load==1, then
* the in value is loaded into the memory location specified by address
* (the loaded value will be emitted to out from the next time step onward).
*/
CHIP RAM8 {
IN in[16], load, address[3];
OUT out[16];
PARTS:
// Put your code here:
DMux8Way(in=load,sel=address,a=a,b=b,c=c,d=d,e=e,f=f,g=g,h=h);
Register(in=in,load=a,out=out1);
Register(in=in,load=b,out=out2);
Register(in=in,load=c,out=out3);
Register(in=in,load=d,out=out4);
Register(in=in,load=e,out=out5);
Register(in=in,load=f,out=out6);
Register(in=in,load=g,out=out7);
Register(in=in,load=h,out=out8);
Mux8Way16(a=out1,b=out2,c=out3,d=out4,e=out5,f=out6,g=out7,h=out8,sel=address,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/03/a/Register.hdl
/**
* 16-bit register:
* If load[t] == 1 then out[t+1] = in[t]
* else out does not change
*/
CHIP Register {
IN in[16], load;
OUT out[16];
PARTS:
// Put your code here:
Bit(in=in[0],load=load,out=out[0]);
Bit(in=in[1],load=load,out=out[1]);
Bit(in=in[2],load=load,out=out[2]);
Bit(in=in[3],load=load,out=out[3]);
Bit(in=in[4],load=load,out=out[4]);
Bit(in=in[5],load=load,out=out[5]);
Bit(in=in[6],load=load,out=out[6]);
Bit(in=in[7],load=load,out=out[7]);
Bit(in=in[8],load=load,out=out[8]);
Bit(in=in[9],load=load,out=out[9]);
Bit(in=in[10],load=load,out=out[10]);
Bit(in=in[11],load=load,out=out[11]);
Bit(in=in[12],load=load,out=out[12]);
Bit(in=in[13],load=load,out=out[13]);
Bit(in=in[14],load=load,out=out[14]);
Bit(in=in[15],load=load,out=out[15]);
}