mirror of
https://github.com/soconnor0919/eceg431.git
synced 2025-12-10 06:04:43 -05:00
project01: Comments/cleanup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
12
01/Mux.hdl
12
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
14
01/Xor.hdl
14
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);
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user