diff --git a/00/Off.hdl b/00/Off.hdl index 9d6b464..6377855 100755 --- a/00/Off.hdl +++ b/00/Off.hdl @@ -13,7 +13,6 @@ CHIP Off { OUT out; PARTS: - // Put your code here: - // Nand(a=true, b=false, out=out); // old + // always output false Nand(a=true, b=true, out=out); } diff --git a/01/And.hdl b/01/And.hdl index ada4be7..c78b333 100644 --- a/01/And.hdl +++ b/01/And.hdl @@ -11,7 +11,7 @@ CHIP And { OUT out; PARTS: - // And = Not(Nand) + // Nand = Not(Nand), so And = Not(Nand) Nand(a=a, b=b, out=tmp); Not(in=tmp, out=out); } diff --git a/01/DMux.hdl b/01/DMux.hdl index dfe0b1e..e47b62b 100644 --- a/01/DMux.hdl +++ b/01/DMux.hdl @@ -12,7 +12,10 @@ CHIP DMux { OUT a, b; PARTS: - Not(in=sel, out=tmp); - And(a=in, b=tmp, out=a); + // invert sel + Not(in=sel, out=notSel); + // when sel=0: a gets in + And(a=in, b=notSel, out=a); + // when sel=1: b gets in And(a=in, b=sel, out=b); } diff --git a/01/DMux4Way.hdl b/01/DMux4Way.hdl index 70028d6..ec2d0ff 100644 --- a/01/DMux4Way.hdl +++ b/01/DMux4Way.hdl @@ -14,7 +14,9 @@ CHIP DMux4Way { OUT a, b, c, d; PARTS: - DMux(in=in, sel=sel[1], a=tmp1, b=tmp2); - DMux(in=tmp1, sel=sel[0], a=a, b=b); - DMux(in=tmp2, sel=sel[0], a=c, b=d); + // sel[1] split in to two groups + DMux(in=in, sel=sel[1], a=lowGroup, b=highGroup); + // sel[0] split each group to out + DMux(in=lowGroup, sel=sel[0], a=a, b=b); + DMux(in=highGroup, sel=sel[0], a=c, b=d); } diff --git a/01/DMux8Way.hdl b/01/DMux8Way.hdl index b598823..bfe3022 100644 --- a/01/DMux8Way.hdl +++ b/01/DMux8Way.hdl @@ -18,7 +18,9 @@ CHIP DMux8Way { OUT a, b, c, d, e, f, g, h; PARTS: - DMux(in=in, sel=sel[2], a=tmp1, b=tmp2); - DMux4Way(in=tmp1, sel=sel[0..1], a=a, b=b, c=c, d=d); - DMux4Way(in=tmp2, sel=sel[0..1], a=e, b=f, c=g, d=h); + // sel[2] split in to two groups of 4 + DMux(in=in, sel=sel[2], a=lowGroup, b=highGroup); + // sel[0..1] split each group to out + DMux4Way(in=lowGroup, sel=sel[0..1], a=a, b=b, c=c, d=d); + DMux4Way(in=highGroup, sel=sel[0..1], a=e, b=f, c=g, d=h); } diff --git a/01/Mux.hdl b/01/Mux.hdl index 422cae7..bce60f4 100644 --- a/01/Mux.hdl +++ b/01/Mux.hdl @@ -11,8 +11,12 @@ CHIP Mux { OUT out; PARTS: - Not(in=sel, out=tmp1); - And(a=a, b=tmp1, out=tmp2); - And(a=b, b=sel, out=tmp3); - Or(a=tmp2, b=tmp3, out=out); + // invert selector + Not(in=sel, out=notSel); + // when sel=0: aPath gets a + And(a=a, b=notSel, out=aPath); + // when sel=1: bPath gets b + And(a=b, b=sel, out=bPath); + // combine both paths + Or(a=aPath, b=bPath, out=out); } diff --git a/01/Mux4Way16.hdl b/01/Mux4Way16.hdl index 8b62e8f..92ec13c 100644 --- a/01/Mux4Way16.hdl +++ b/01/Mux4Way16.hdl @@ -14,7 +14,9 @@ CHIP Mux4Way16 { OUT out[16]; PARTS: - Mux16(a=a, b=b, sel=sel[0], out=tmp1); - Mux16(a=c, b=d, sel=sel[0], out=tmp2); - Mux16(a=tmp1, b=tmp2, sel=sel[1], out=out); + // sel[0] pick from each group + Mux16(a=a, b=b, sel=sel[0], out=lowGroup); // group ab + Mux16(a=c, b=d, sel=sel[0], out=highGroup); // group cd + // sel[1] pick which group + Mux16(a=lowGroup, b=highGroup, sel=sel[1], out=out); } diff --git a/01/Mux8Way16.hdl b/01/Mux8Way16.hdl index 57c541b..2173699 100644 --- a/01/Mux8Way16.hdl +++ b/01/Mux8Way16.hdl @@ -20,7 +20,9 @@ CHIP Mux8Way16 { OUT out[16]; PARTS: - Mux4Way16(a=a, b=b, c=c, d=d, sel=sel[0..1], out=tmp1); - Mux4Way16(a=e, b=f, c=g, d=h, sel=sel[0..1], out=tmp2); - Mux16(a=tmp1, b=tmp2, sel=sel[2], out=out); + // sel[0..1] pick from each group + Mux4Way16(a=a, b=b, c=c, d=d, sel=sel[0..1], out=lowGroup); // group abcd + Mux4Way16(a=e, b=f, c=g, d=h, sel=sel[0..1], out=highGroup); // group efgh + // sel[2] pick which group + Mux16(a=lowGroup, b=highGroup, sel=sel[2], out=out); } diff --git a/01/Or8Way.hdl b/01/Or8Way.hdl index 498820e..83cdfc7 100644 --- a/01/Or8Way.hdl +++ b/01/Or8Way.hdl @@ -11,11 +11,14 @@ CHIP Or8Way { OUT out; PARTS: - Or(a=in[0], b=in[1], out=tmp1); - Or(a=in[2], b=in[3], out=tmp2); - Or(a=in[4], b=in[5], out=tmp3); - Or(a=in[6], b=in[7], out=tmp4); - Or(a=tmp1, b=tmp2, out=tmp5); - Or(a=tmp3, b=tmp4, out=tmp6); - Or(a=tmp5, b=tmp6, out=out); + // combine pairs + Or(a=in[0], b=in[1], out=pair0); + Or(a=in[2], b=in[3], out=pair1); + Or(a=in[4], b=in[5], out=pair2); + Or(a=in[6], b=in[7], out=pair3); + // combine groups of pairs + Or(a=pair0, b=pair1, out=lowGroup); + Or(a=pair2, b=pair3, out=highGroup); + // combine both groups + Or(a=lowGroup, b=highGroup, out=out); } diff --git a/01/Xor.hdl b/01/Xor.hdl index c6229a8..ad4dacd 100644 --- a/01/Xor.hdl +++ b/01/Xor.hdl @@ -11,9 +11,13 @@ CHIP Xor { OUT out; PARTS: - Not(in=a, out=tmp1); - Not(in=b, out=tmp2); - And(a=a, b=tmp2, out=tmp3); - And(a=tmp1, b=b, out=tmp4); - Or(a=tmp3, b=tmp4, out=out); + // invert both inputs + Not(in=a, out=notA); + Not(in=b, out=notB); + // a and not b path + And(a=a, b=notB, out=aPath); + // not a and b path + And(a=notA, b=b, out=bPath); + // combine both paths + Or(a=aPath, b=bPath, out=out); } diff --git a/01/chapter1lecture.pdf b/01/chapter1lecture.pdf deleted file mode 100644 index cf0d9f2..0000000 Binary files a/01/chapter1lecture.pdf and /dev/null differ