/3/1/PC.hdl

http://github.com/happy4crazy/elements_of_computing_systems · Unknown · 26 lines · 22 code · 4 blank · 0 comment · 0 complexity · 4ebc907845a2912bfdb5d979da990a7e 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/03/1/PC.hdl
  5. /**
  6. * 16-bit counter with load and reset controls.
  7. *
  8. * If reset(t-1) then out(t) = 0
  9. * else if load(t-1) then out(t) = in(t-1)
  10. * else if inc(t-1) then out(t) = out(t-1) + 1 (integer addition)
  11. * else out(t) = out(t-1)
  12. */
  13. CHIP PC {
  14. IN in[16], load, inc, reset;
  15. OUT out[16];
  16. PARTS:
  17. Register(in=registerInput, load=true, out=out, out=previousOutput);
  18. Inc16(in=previousOutput, out=incrementedPreviousOutput);
  19. Mux16(a=previousOutput, b=incrementedPreviousOutput, sel=inc, out=incOutput);
  20. Mux16(a=incOutput, b=in, sel=load, out=loadedOutput);
  21. Mux16(a=loadedOutput, b=false, sel=reset, out=registerInput);
  22. }