/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. * 8-way 16-bit multiplexor.
  7. * out = a -- if sel=000
  8. * b -- if sel=001
  9. * c -- if sel=010
  10. * d -- if sel=011
  11. * ...
  12. * h -- if sel=111
  13. */
  14. /**
  15. * Note that the numerical value of x[k] is x[k] * 2^k
  16. * So if sel=100, then sel[0] = 0, sel[1] = 0, and sel[2] = 1
  17. * This tripped me up because I was reading the bits in the wrong direction!
  18. */
  19. CHIP Mux8Way16 {
  20. IN a[16], b[16], c[16], d[16],
  21. e[16], f[16], g[16], h[16],
  22. sel[3];
  23. OUT out[16];
  24. PARTS:
  25. Mux4Way16(a=a, b=b, c=c, d=d, sel=sel[0..1], out=abcd);
  26. Mux4Way16(a=e, b=f, c=g, d=h, sel=sel[0..1], out=efgh);
  27. Mux16(a=abcd, b=efgh, sel=sel[2], out=out);
  28. }