add project 1, 2, 3 HDLs
This commit is contained in:
20
projects/03/a/Bit.hdl
Normal file
20
projects/03/a/Bit.hdl
Normal file
@@ -0,0 +1,20 @@
|
||||
// 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:
|
||||
Mux(a=dffout, b=in, sel=load, out=muxout);
|
||||
DFF(in=muxout, out=out, out=dffout);
|
||||
}
|
25
projects/03/a/PC.hdl
Normal file
25
projects/03/a/PC.hdl
Normal 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/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:
|
||||
Inc16(in=registerValue, out=incrementedValue);
|
||||
Mux16(a=registerValue, b=incrementedValue, sel=inc, out=incBitStep);
|
||||
Mux16(a=incBitStep, b=in, sel=load, out=loadBitStep);
|
||||
Mux16(a=loadBitStep, b=false, sel=reset, out=resetBitStep);
|
||||
Register(in=resetBitStep, load=true, out=out, out=registerValue);
|
||||
}
|
45
projects/03/a/RAM64.hdl
Normal file
45
projects/03/a/RAM64.hdl
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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=address[3..5], a=toRAM8A,
|
||||
b=toRAM8B,
|
||||
c=toRAM8C,
|
||||
d=toRAM8D,
|
||||
e=toRAM8E,
|
||||
f=toRAM8F,
|
||||
g=toRAM8G,
|
||||
h=toRAM8H);
|
||||
|
||||
RAM8(in=in, load=toRAM8A, address=address[0..2], out=fromRAM8A);
|
||||
RAM8(in=in, load=toRAM8B, address=address[0..2], out=fromRAM8B);
|
||||
RAM8(in=in, load=toRAM8C, address=address[0..2], out=fromRAM8C);
|
||||
RAM8(in=in, load=toRAM8D, address=address[0..2], out=fromRAM8D);
|
||||
RAM8(in=in, load=toRAM8E, address=address[0..2], out=fromRAM8E);
|
||||
RAM8(in=in, load=toRAM8F, address=address[0..2], out=fromRAM8F);
|
||||
RAM8(in=in, load=toRAM8G, address=address[0..2], out=fromRAM8G);
|
||||
RAM8(in=in, load=toRAM8H, address=address[0..2], out=fromRAM8H);
|
||||
|
||||
Mux8Way16(sel=address[3..5], out=out, a=fromRAM8A,
|
||||
b=fromRAM8B,
|
||||
c=fromRAM8C,
|
||||
d=fromRAM8D,
|
||||
e=fromRAM8E,
|
||||
f=fromRAM8F,
|
||||
g=fromRAM8G,
|
||||
h=fromRAM8H);
|
||||
}
|
45
projects/03/a/RAM8.hdl
Normal file
45
projects/03/a/RAM8.hdl
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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=toRegisterA,
|
||||
b=toRegisterB,
|
||||
c=toRegisterC,
|
||||
d=toRegisterD,
|
||||
e=toRegisterE,
|
||||
f=toRegisterF,
|
||||
g=toRegisterG,
|
||||
h=toRegisterH);
|
||||
|
||||
Register(in=in, load=toRegisterA, out=fromRegisterA);
|
||||
Register(in=in, load=toRegisterB, out=fromRegisterB);
|
||||
Register(in=in, load=toRegisterC, out=fromRegisterC);
|
||||
Register(in=in, load=toRegisterD, out=fromRegisterD);
|
||||
Register(in=in, load=toRegisterE, out=fromRegisterE);
|
||||
Register(in=in, load=toRegisterF, out=fromRegisterF);
|
||||
Register(in=in, load=toRegisterG, out=fromRegisterG);
|
||||
Register(in=in, load=toRegisterH, out=fromRegisterH);
|
||||
|
||||
Mux8Way16(sel=address, out=out, a=fromRegisterA,
|
||||
b=fromRegisterB,
|
||||
c=fromRegisterC,
|
||||
d=fromRegisterD,
|
||||
e=fromRegisterE,
|
||||
f=fromRegisterF,
|
||||
g=fromRegisterG,
|
||||
h=fromRegisterH);
|
||||
}
|
34
projects/03/a/Register.hdl
Normal file
34
projects/03/a/Register.hdl
Normal 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]);
|
||||
}
|
Reference in New Issue
Block a user