25 lines
520 B
Plaintext
25 lines
520 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/01/Mux.hdl
|
|
|
|
/**
|
|
* Multiplexor:
|
|
* out = a if sel == 0
|
|
* b otherwise
|
|
*/
|
|
|
|
CHIP Mux {
|
|
IN a, b, sel;
|
|
OUT out;
|
|
|
|
PARTS:
|
|
Not(in=a,out=negA);
|
|
Not(in=b,out=negB);
|
|
Not(in=sel,out=negSel);
|
|
And(a=a,b=b,out=out1);
|
|
And(a=a,b=negSel,out=out2);
|
|
And(a=b,b=sel,out=out3);
|
|
Or(a=out1,b=out2,out=xOut);
|
|
Or(a=xOut,b=out3,out=out);
|
|
} |