/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
- // This file is part of the materials accompanying the book
- // "The Elements of Computing Systems" by Nisan and Schocken,
- // MIT Press. Book site: www.idc.ac.il/tecs
- // File name: projects/03/1/PC.hdl
-
- /**
- * 16-bit counter with load and reset controls.
- *
- * If reset(t-1) then out(t) = 0
- * else if load(t-1) then out(t) = in(t-1)
- * else if inc(t-1) then out(t) = out(t-1) + 1 (integer addition)
- * else out(t) = out(t-1)
- */
-
- CHIP PC {
-
- IN in[16], load, inc, reset;
- OUT out[16];
-
- PARTS:
- Register(in=registerInput, load=true, out=out, out=previousOutput);
- Inc16(in=previousOutput, out=incrementedPreviousOutput);
- Mux16(a=previousOutput, b=incrementedPreviousOutput, sel=inc, out=incOutput);
- Mux16(a=incOutput, b=in, sel=load, out=loadedOutput);
- Mux16(a=loadedOutput, b=false, sel=reset, out=registerInput);
- }