-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPC.hdl
24 lines (22 loc) · 781 Bytes
/
PC.hdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* A 16-bit counter with load and reset control bits.
* if (reset[t] == 1) out[t+1] = 0
* else if (load[t] == 1) out[t+1] = in[t]
* else if (inc[t] == 1) out[t+1] = out[t] + 1 (integer addition)
* else out[t+1] = out[t]
*/
CHIP PC {
IN in[16],load,inc,reset;
OUT out[16];
PARTS:
Mux16(a=outIn, b=in, sel=load, out=outMuxA);
Mux16(a=outMuxA, b=false, sel=reset, out=outMuxB);
Or(a=load, b=reset, out=loadOrReset);
Inc16(in=outMuxB, out=outInc);
Not(in=load, out=notLoad);
Not(in=reset, out=notReset);
And(a=notLoad, b=notReset, out=notLR);
And(a=inc, b=notLR, out=incAndNotLR);
Mux16(a=outMuxB, b=outInc, sel=incAndNotLR, out=outMuxC);
Register(in=outMuxC, load=true, out=outIn, out=out);
}