Trying to build a PC (counter) for a nand2tetris book, but I have some logic issues

Here is my code:

CHIP PC { IN in[16],load,inc,reset; OUT out[16]; PARTS: Inc16(in = regout, out = incout); Mux16(a = regout, b = incout, sel = inc, out = incdecision); Mux16(a = incdecision, b = false, sel = reset, out = resetdecision); Mux16(a = regout, b = resetdecision, sel = load, out = loaddecision); Register(in = loaddecision, load = true, out = regout, out = out); } 

Basically, the value coming out of the register increases, which is accepted only if inc is 1 (checked through Mux), which then passes through another Mux, which can reset, and then another Mux, which may or cannot write its depending on the value of the load. Then any value out of this (whether it is a changed value or a value coming from the old register) is placed in the register.

What am I doing wrong?

+4
source share
3 answers

It seems that the In signal is not connected to anything. If the load signal is set, you need to get the appropriate Mux16 to load the In value into the register.

+2
source

resetdecision and loaddecesion . The first has a higher priority.

 Inc16(in=outpc, out=outincreased); Mux16(a=outpc, b=outincreased, sel=inc, out=outinc); Mux16(a=outinc, b=in, sel=load, out=outload); Mux16(a=outload, b=false, sel=reset, out=outreset); //And16(a=outLOAD, b[0..15]=reset, out=outreset); Register(in=outreset, load=true, out=out, out=outpc); 
+2
source

reset Mux16 should happen after booting Mux16. The Mux16 load must have "in" as pin "b".

My working code from Nand2Tetris:

 Inc16(in = outandabout, out = incout); Mux16( a = outandabout, b = incout, sel = inc, out = incinc); Mux16( a = incinc, b = in, sel = load, out = loadout); Mux16( a = loadout, b = false, sel = reset, out= outreset); Register(in = outreset, load = true, out = out, out = outandabout); 
0
source

All Articles