Skip to content

Commit

Permalink
Program counter
Browse files Browse the repository at this point in the history
  • Loading branch information
icmor committed May 17, 2024
1 parent 1332450 commit 1ecc741
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sequentialChips/PC.hdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/3/a/PC.hdl
/**
* A 16-bit counter.
* if reset(t): out(t+1) = 0
* else if load(t): out(t+1) = in(t)
* else if inc(t): out(t+1) = out(t) + 1
* else out(t+1) = out(t)
*/
CHIP PC {
IN in[16], inc, load, reset;
OUT out[16];

PARTS:
Inc16(in=regout, out=increg);
Mux16(a=regout, b=increg, sel=inc, out=ri);
Mux16(a=ri, b=in, sel=load, out=ril);
Mux16(a=ril, b=false, sel=reset, out=regin);
Register(in=regin, load=true, out=regout, out=out);
}

0 comments on commit 1ecc741

Please sign in to comment.