/1/Mux.hdl

http://github.com/happy4crazy/elements_of_computing_systems · Unknown · 21 lines · 17 code · 4 blank · 0 comment · 0 complexity · f940861c89c82bf752303eaa0ecf934a 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/Mux.hdl
  5. /**
  6. * Multiplexor. If sel=0 then out = a else out = b.
  7. * In other words, mux(a,b,s) = a!s + bs
  8. */
  9. CHIP Mux {
  10. IN a, b, sel;
  11. OUT out;
  12. PARTS:
  13. Not(in=sel,out=notsel);
  14. And(a=a, b=notsel, out=left);
  15. And(a=b, b=sel, out=right);
  16. Or(a=left, b=right, out=out);
  17. }