# Struggling with Program Counter (PC)

6 messages
Open this post in threaded view
|

## Struggling with Program Counter (PC)

Open this post in threaded view
|

## Re: Struggling with Program Counter (PC)

 Administrator You've got two Register parts in your design, but a program counter only stores a single value, hence it only needs one Register. Think of the PC as a circuit that has different behaviors depending on the three inputs and first make circuits that just have each of the designed behaviors: increment, load, reset, and hold. What are the differences between these circuits? Can you use Mux16 parts (or other parts) to be able to change between the different behaviors? Now all you need to do is figure out how to use the three input signals to control the multiplexer select inputs.
Open this post in threaded view
|

## Re: Struggling with Program Counter (PC)

 It was getting pretty late when wrote and posted that code. Here are the building blocks I've been trying to work with. The previously posted code shows my frustration in wiring the circuit leading to two registers. I basically just tried to mash the puzzle pieces together. Reset: Mux16(a=?, b=false, sel=reset, out=?); Load: Idea 1: Register(in=in, load=load, out=out); Idea 2: Mux16(a=?, b=in, sel=load, out=toReg);         Register(in=toReg, load=load, out=out); Inc: Mux16(a=?, b=fromInc, sel=inc, out=toReg); Register(in=toReg, load=true, out=toInc, out=?); Inc16(in=toInc, out=fromInc); Selection Logic Idea: Mux4Way16(a=?, b=?, c=?, d=?, sel[1]=inc, sel[0]=reset, out=out);
Open this post in threaded view
|

## Re: Struggling with Program Counter (PC)

 Administrator The thing you need to note is that the only difference between the various behaviors is what gets applied to the input port of the Register part. Using a Mux4Way16 is a perfectly reasonable way to go and makes things pretty simple in the end. But you have two select inputs but three control signals. So you need a little circuit to take the three control signals and map them to the two select signals of the mux. The simplest way to do that is to make a truth table showing all eight possible combinations of the three control signals and have a column for the desired behavior (of which there are four). Then you can assign one of the four possible select signal combinations to each of the behaviors (conceptually it doesn't matter, but certain choices make the resulting logic a bit simpler, but not enough to spend too much time fretting over it -- pick one and push one). Then you just need to apply the signal that needs to make it to the Register input port to the appropriate mux input.