Files
eceg431/01/Mux.hdl

23 lines
550 B
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/1/Mux.hdl
/**
* Multiplexor:
* if (sel = 0) out = a, else out = b
*/
CHIP Mux {
IN a, b, sel;
OUT out;
PARTS:
// 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);
}