Re: Stuck on PC
Posted by WBahn on Nov 23, 2019; 12:07am
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Stuck-on-PC-tp4033903p4033916.html
I find that it really helps to draw the schematic of what the HDL represented, but that may be more reflective of my particular background than anything else.
Ask yourself under what circumstances the value stored in the Register should change. Your current design only changes this value when the 'load' signal is asserted. But what if just the 'reset' signal is asserted? Is it enough to just have the output for the current clock cycle be low? What about the next clock cycle? Consider the following:
Let's say that t = 513 and we have the following:
out[t=513] = 10000
in[t=513] = 12345
reset[t=513] = 1
inc[t=513] = 0
load[t=513] = 0
The specs say:
/**
* 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]
*/
So out[t=514] should be 0. Your circuit actually makes the output at t=513 equal to 0 because the effect of your control signals on the Muxes routes the False (0) to the output immediately upon the control signals changing.
But aside from that (i.e., let's assume that your circuit made out[t=514] equal to zero like it should), what about the next clock cycle if
out[t=514] = 0
in[t=514] = 12345
reset[t=514] = 0
inc[t=514] = 1
load[t=514] = 0
In this case the output at t=515 should be 1, but your circuit still has 10000 stored in the Register, so your output will go to 10001, which is definitely not what you want.
For any situation in which the new output is related to the prior output, your circuit must store that prior output so that it can use it during the next clock cycle. So what you are really controlling is the value to be stored in the register on each clock cycle. Look at the problem from that perspective.