diff --git a/01/DMux4Way.hdl b/01/DMux4Way.hdl index 399729e..f88187e 100644 --- a/01/DMux4Way.hdl +++ b/01/DMux4Way.hdl @@ -14,5 +14,8 @@ CHIP DMux4Way { OUT a, b, c, d; PARTS: - //// Replace this comment with your code. -} \ No newline at end of file + // Use two levels of DMux: first level splits by sel[1], second level splits by sel[0] + DMux(in=in, sel=sel[1], a=dmuxAB, b=dmuxCD); + DMux(in=dmuxAB, sel=sel[0], a=a, b=b); + DMux(in=dmuxCD, sel=sel[0], a=c, b=d); +} diff --git a/01/DMux8Way.hdl b/01/DMux8Way.hdl index e3d3dca..f7c3a05 100644 --- a/01/DMux8Way.hdl +++ b/01/DMux8Way.hdl @@ -18,5 +18,8 @@ CHIP DMux8Way { OUT a, b, c, d, e, f, g, h; PARTS: - //// Replace this comment with your code. + // Use one DMux and two DMux4Way gates: first split by sel[2], then each half by sel[0..1] + DMux(in=in, sel=sel[2], a=dmuxABCD, b=dmuxEFGH); + DMux4Way(in=dmuxABCD, sel=sel[0..1], a=a, b=b, c=c, d=d); + DMux4Way(in=dmuxEFGH, sel=sel[0..1], a=e, b=f, c=g, d=h); } diff --git a/01/Mux4Way16.hdl b/01/Mux4Way16.hdl index 8d6b645..8cc1223 100644 --- a/01/Mux4Way16.hdl +++ b/01/Mux4Way16.hdl @@ -12,7 +12,10 @@ CHIP Mux4Way16 { IN a[16], b[16], c[16], d[16], sel[2]; OUT out[16]; - + PARTS: - //// Replace this comment with your code. -} \ No newline at end of file + // Use two levels of Mux16: first level selects between pairs, second level selects final output + Mux16(a=a, b=b, sel=sel[0], out=muxAB); + Mux16(a=c, b=d, sel=sel[0], out=muxCD); + Mux16(a=muxAB, b=muxCD, sel=sel[1], out=out); +} diff --git a/01/Mux8Way16.hdl b/01/Mux8Way16.hdl index 4fe712e..762a249 100644 --- a/01/Mux8Way16.hdl +++ b/01/Mux8Way16.hdl @@ -20,5 +20,8 @@ CHIP Mux8Way16 { OUT out[16]; PARTS: - //// Replace this comment with your code. + // Use two Mux4Way16 gates and one Mux16 to select from 8 inputs + Mux4Way16(a=a, b=b, c=c, d=d, sel=sel[0..1], out=mux4wayABCD); + Mux4Way16(a=e, b=f, c=g, d=h, sel=sel[0..1], out=mux4wayEFGH); + Mux16(a=mux4wayABCD, b=mux4wayEFGH, sel=sel[2], out=out); } diff --git a/01/Or8Way.hdl b/01/Or8Way.hdl index 6eff8a2..82d456f 100644 --- a/01/Or8Way.hdl +++ b/01/Or8Way.hdl @@ -3,7 +3,7 @@ // by Nisan and Schocken, MIT Press. // File name: projects/1/Or8Way.hdl /** - * 8-way Or gate: + * 8-way Or gate: * out = in[0] Or in[1] Or ... Or in[7] */ CHIP Or8Way { @@ -11,5 +11,12 @@ CHIP Or8Way { OUT out; PARTS: - //// Replace this comment with your code. -} \ No newline at end of file + // Chain Or gates to combine all 8 inputs + Or(a=in[0], b=in[1], out=or01); + Or(a=in[2], b=in[3], out=or23); + Or(a=in[4], b=in[5], out=or45); + Or(a=in[6], b=in[7], out=or67); + Or(a=or01, b=or23, out=or0123); + Or(a=or45, b=or67, out=or4567); + Or(a=or0123, b=or4567, out=out); +}