project01: Comments/cleanup

This commit is contained in:
2025-09-03 22:10:34 -04:00
parent dd31b8f1dc
commit 934f1ad2f5
11 changed files with 54 additions and 33 deletions

View File

@@ -13,7 +13,6 @@ CHIP Off {
OUT out; OUT out;
PARTS: PARTS:
// Put your code here: // always output false
// Nand(a=true, b=false, out=out); // old
Nand(a=true, b=true, out=out); Nand(a=true, b=true, out=out);
} }

View File

@@ -11,7 +11,7 @@ CHIP And {
OUT out; OUT out;
PARTS: PARTS:
// And = Not(Nand) // Nand = Not(Nand), so And = Not(Nand)
Nand(a=a, b=b, out=tmp); Nand(a=a, b=b, out=tmp);
Not(in=tmp, out=out); Not(in=tmp, out=out);
} }

View File

@@ -12,7 +12,10 @@ CHIP DMux {
OUT a, b; OUT a, b;
PARTS: PARTS:
Not(in=sel, out=tmp); // invert sel
And(a=in, b=tmp, out=a); 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); And(a=in, b=sel, out=b);
} }

View File

@@ -14,7 +14,9 @@ CHIP DMux4Way {
OUT a, b, c, d; OUT a, b, c, d;
PARTS: PARTS:
DMux(in=in, sel=sel[1], a=tmp1, b=tmp2); // sel[1] split in to two groups
DMux(in=tmp1, sel=sel[0], a=a, b=b); DMux(in=in, sel=sel[1], a=lowGroup, b=highGroup);
DMux(in=tmp2, sel=sel[0], a=c, b=d); // 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);
} }

View File

@@ -18,7 +18,9 @@ CHIP DMux8Way {
OUT a, b, c, d, e, f, g, h; OUT a, b, c, d, e, f, g, h;
PARTS: PARTS:
DMux(in=in, sel=sel[2], a=tmp1, b=tmp2); // sel[2] split in to two groups of 4
DMux4Way(in=tmp1, sel=sel[0..1], a=a, b=b, c=c, d=d); DMux(in=in, sel=sel[2], a=lowGroup, b=highGroup);
DMux4Way(in=tmp2, sel=sel[0..1], a=e, b=f, c=g, d=h); // 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);
} }

View File

@@ -11,8 +11,12 @@ CHIP Mux {
OUT out; OUT out;
PARTS: PARTS:
Not(in=sel, out=tmp1); // invert selector
And(a=a, b=tmp1, out=tmp2); Not(in=sel, out=notSel);
And(a=b, b=sel, out=tmp3); // when sel=0: aPath gets a
Or(a=tmp2, b=tmp3, out=out); 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);
} }

View File

@@ -14,7 +14,9 @@ CHIP Mux4Way16 {
OUT out[16]; OUT out[16];
PARTS: PARTS:
Mux16(a=a, b=b, sel=sel[0], out=tmp1); // sel[0] pick from each group
Mux16(a=c, b=d, sel=sel[0], out=tmp2); Mux16(a=a, b=b, sel=sel[0], out=lowGroup); // group ab
Mux16(a=tmp1, b=tmp2, sel=sel[1], out=out); 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);
} }

View File

@@ -20,7 +20,9 @@ CHIP Mux8Way16 {
OUT out[16]; OUT out[16];
PARTS: PARTS:
Mux4Way16(a=a, b=b, c=c, d=d, sel=sel[0..1], out=tmp1); // sel[0..1] pick from each group
Mux4Way16(a=e, b=f, c=g, d=h, sel=sel[0..1], out=tmp2); Mux4Way16(a=a, b=b, c=c, d=d, sel=sel[0..1], out=lowGroup); // group abcd
Mux16(a=tmp1, b=tmp2, sel=sel[2], out=out); 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);
} }

View File

@@ -11,11 +11,14 @@ CHIP Or8Way {
OUT out; OUT out;
PARTS: PARTS:
Or(a=in[0], b=in[1], out=tmp1); // combine pairs
Or(a=in[2], b=in[3], out=tmp2); Or(a=in[0], b=in[1], out=pair0);
Or(a=in[4], b=in[5], out=tmp3); Or(a=in[2], b=in[3], out=pair1);
Or(a=in[6], b=in[7], out=tmp4); Or(a=in[4], b=in[5], out=pair2);
Or(a=tmp1, b=tmp2, out=tmp5); Or(a=in[6], b=in[7], out=pair3);
Or(a=tmp3, b=tmp4, out=tmp6); // combine groups of pairs
Or(a=tmp5, b=tmp6, out=out); Or(a=pair0, b=pair1, out=lowGroup);
Or(a=pair2, b=pair3, out=highGroup);
// combine both groups
Or(a=lowGroup, b=highGroup, out=out);
} }

View File

@@ -11,9 +11,13 @@ CHIP Xor {
OUT out; OUT out;
PARTS: PARTS:
Not(in=a, out=tmp1); // invert both inputs
Not(in=b, out=tmp2); Not(in=a, out=notA);
And(a=a, b=tmp2, out=tmp3); Not(in=b, out=notB);
And(a=tmp1, b=b, out=tmp4); // a and not b path
Or(a=tmp3, b=tmp4, out=out); 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);
} }

Binary file not shown.