Posted by
hdllearn on
May 09, 2024; 7:15am
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Mux4Way16-tp4037818p4037835.html
HIP Mux4Way16 {
IN a[16], b[16], c[16], d[16], sel[2];
OUT out[16];
PARTS:
////And, Or, Not, Xor, Mux, Mux16, And16, Or16, Not16
//// Replace this comment with your code.
Not(in=sel[0], out=notsela);
Not(in=sel[1], out=notselb);
//00. outand7=0
And(a=sel[1], b=sel[0], out=outand7);
Not(in=outand7, out=notoutand7);
And(a=notoutand7, b=notoutand7, out=out00);
//10. outand8=1
And(a=outand7, b=sel[1], out=outand8);
////sel=01 or sel=10
//Good
And(a=sel[0], b=sel[1], out=outxor1);
///sel=01
///And(a=outxor1, b=notselb, out=out10);
Or(a=outxor1, b=notselb, out=out10);
////sel=11
Or(a=outxor1, b=notsela, out=out11);
//outa, outb, outc, outd are all good
//sel=00
Mux16(a=a, b=b, sel=outand7, out=outa);
//sel=10
Mux16(a=c, b=d, sel=outand8, out=outc);
//sel=01
Mux16(a=a, b=b, sel=out10, out=outb);
//sel=11
Mux16(a=c, b=d, sel=out11, out=outd);
//Algo"
//gates we have: And, And16, Or, Or16, Or8way, Not, Not16, Mux, Mux16, DMux, Nand
//NB:Or will bitwise Or for 16 bits of 2, 16 bits.
//We need a SWITCH to switch between a[16], b[16], c[16], d[16]
//Therefore cannot use And16, Or16
//a or b or c or d
//Or8Way(in[0]=outand7, in[1]=outand8, in[2]=out10, in[3]=out11, out= interout);
Or8Way(in[0]=outand7, in[1]=out11, out=interaord);
//And(a=interout, b=outand7, )
//Mux16(a=outa, b=outd, sel=outand7, out=finala);
//Mux16(a=outb, b=outc, sel=out10, out=finalb);
}
John