Files
N2T/projects/01/DMux8Way.hdl
2020-11-15 13:57:48 -05:00

43 lines
1.4 KiB
Plaintext

// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux8Way.hdl
/**
* 8-way demultiplexor:
* {a, b, c, d, e, f, g, h} = {in, 0, 0, 0, 0, 0, 0, 0} if sel == 000
* {0, in, 0, 0, 0, 0, 0, 0} if sel == 001
* etc.
* {0, 0, 0, 0, 0, 0, 0, in} if sel == 111
*/
CHIP DMux8Way {
IN in, sel[3];
OUT a, b, c, d, e, f, g, h;
PARTS:
// Put your code here:
Not(in=sel[0], out=notsel0);
Not(in=sel[1], out=notsel1);
Not(in=sel[2], out=notsel2);
/* Create one selector signal for each of the eight cases. */
And3(a=notsel0, b=notsel1, c=notsel2, out=sela);
And3(a=sel[0], b=notsel1, c=notsel2, out=selb);
And3(a=notsel0, b=sel[1], c=notsel2, out=selc);
And3(a=sel[0], b=sel[1], c=notsel2, out=seld);
And3(a=notsel0, b=notsel1, c=sel[2], out=sele);
And3(a=sel[0], b=notsel1, c=sel[2], out=self);
And3(a=notsel0, b=sel[1], c=sel[2], out=selg);
And3(a=sel[0], b=sel[1], c=sel[2], out=selh);
And(a=in, b=sela, out=a);
And(a=in, b=selb, out=b);
And(a=in, b=selc, out=c);
And(a=in, b=seld, out=d);
And(a=in, b=sele, out=e);
And(a=in, b=self, out=f);
And(a=in, b=selg, out=g);
And(a=in, b=selh, out=h);
}