-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mux.hdl
49 lines (43 loc) · 1.04 KB
/
Mux.hdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Mux gate: out = Or(
* And( a , Not(b), Not(sel) ),
* And( a , b , Not(sel) ),
* And( Not(a), b , sel ),
* And( a , b , sel )
* )
*
* a b sel out
* ------------
* 0 0 0 0
* 0 1 1 0
* 0 0 0 1
* 0 1 1 1
* 1 0 0 0
* 1 1 1 1
* 1 0 0 0
* 1 1 1 1
*
*/
CHIP Mux {
IN a, b, sel;
OUT out;
PARTS:
// And( a, Not(b), Not(sel) )
Not(in=b, out=notB);
Not(in=sel, out=notSel);
And(a=a, b=notB, out=andAnotB);
And(a=andAnotB, b=notSel, out=r1);
// And( a, b, Not(sel) )
And(a=a, b=b, out=andAB);
And(a=andAB, b=notSel, out=r2);
// And( Not(a), b, sel )
Not(in=a, out=notA);
And(a=notA, b=b, out=andNotAB);
And(a=andNotAB, b=sel, out=r3);
// And( a, b, sel )
And(a=andAB, b=sel, out=r4);
// Mux( a, b, sel )
Or(a=r1, b=r2, out=r12);
Or(a=r3, b=r4, out=r34);
Or(a=r12, b=r34, out=out);
}