PageRenderTime 100ms CodeModel.GetById 40ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 0ms

/1/Mux8Way16.hdl

http://github.com/happy4crazy/elements_of_computing_systems
Unknown | 34 lines | 28 code | 6 blank | 0 comment | 0 complexity | 25425610dcb1d7423c259dd005a188ca MD5 | raw file
 1// This file is part of the materials accompanying the book 
 2// "The Elements of Computing Systems" by Nisan and Schocken, 
 3// MIT Press. Book site: www.idc.ac.il/tecs
 4// File name: projects/01/Mux8Way16.hdl
 5
 6/**
 7 * 8-way 16-bit multiplexor.  
 8 * out = a -- if sel=000
 9 *       b -- if sel=001
10 *       c -- if sel=010
11 *       d -- if sel=011
12 *       ...
13 *       h -- if sel=111
14 */
15
16/**
17  * Note that the numerical value of x[k] is x[k] * 2^k
18  * So if sel=100, then sel[0] = 0, sel[1] = 0, and sel[2] = 1
19  * This tripped me up because I was reading the bits in the wrong direction!
20 */
21 
22CHIP Mux8Way16 {
23
24    IN  a[16], b[16], c[16], d[16],
25        e[16], f[16], g[16], h[16],
26        sel[3];
27
28    OUT out[16];
29
30    PARTS: 
31    Mux4Way16(a=a, b=b, c=c, d=d, sel=sel[0..1], out=abcd);
32    Mux4Way16(a=e, b=f, c=g, d=h, sel=sel[0..1], out=efgh);
33    Mux16(a=abcd, b=efgh, sel=sel[2], out=out);
34}