PageRenderTime 60ms CodeModel.GetById 20ms app.highlight 0ms RepoModel.GetById 20ms app.codeStats 0ms

/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/**
 7 * 16-bit counter with load and reset controls.
 8 *
 9 * If reset(t-1) then out(t) = 0
10 *    else if load(t-1) then out(t) = in(t-1)
11 *         else if inc(t-1) then out(t) = out(t-1) + 1 (integer addition)
12 *              else out(t) = out(t-1)
13 */
14
15CHIP PC {
16
17    IN  in[16], load, inc, reset;
18    OUT out[16];
19
20    PARTS:
21    Register(in=registerInput, load=true, out=out, out=previousOutput);
22    Inc16(in=previousOutput, out=incrementedPreviousOutput);
23    Mux16(a=previousOutput, b=incrementedPreviousOutput, sel=inc, out=incOutput);
24    Mux16(a=incOutput, b=in, sel=load, out=loadedOutput);
25    Mux16(a=loadedOutput, b=false, sel=reset, out=registerInput);
26}