|
Hi, I'm doing this for me, but I'm stuck on the PC. I've got it working, kind of, it can set a value, increment, reset and return the correct values. But it doesn't pass the test script and it doesn't do the priority of control bits.
My original plan was to pass the in through a set of DMux's creating 4 inputs to a Mux4Way16, but this is simpler, I just don't think the sel0/1 bits are correct.
Here's what I have so far:
CHIP PC {
IN in[16],inc, load, reset;
OUT out[16];
PARTS:
// Register(in=false, load=true, out=out); // Reset
// Register(in=in, load=load, out=out); // Load
// Inc16(in=, out=);
// Use multiplexor to select mode: inc, load, reset
// The inc Mux needs to get the register contents out, Inc16 it and then set it back into the Register.
// Mux16(a=in, b=out, sel=inc, out=muxOut);
// Inc16(in=muxOut, out=incOut);
// Register(in=incOut, load=true, out=out);
// Reset
// Mux16(a=in, b=false, sel=reset, out=resetMuxOut);
// * The input to the Register needs to be set from reset, load and increment,
// such that the next iteration gets that value.
//
// * Need to use two outs from Register such that inc can use the value. It's a feedback loop like in Bit
Inc16(in=regOut, out=incOut);
// TODO: sel=<select logic> Not(in=reset, out=notReset);
Not(in=load, out=notLoad);
Not(in=inc, out=notInc);
And(a=notReset, b=notInc, out=sel0);
And(a=notLoad, b=notInc, out=sel1);
Mux4Way16(
a=incOut, // Increment - load=1
b=in, // Load - load=1
c=false, // Reset - load=1
d=regOut, // else part - Doesn't need to set load=1
sel[0]=sel0,
sel[1]=sel1,
out=muxOut);
// TODO: load=<select logic> Or(a=reset, b=load, out=loadOut1);
Or(a=loadOut1, b=inc, out=loadOut);
Register(in=muxOut, load=loadOut, out=out, out=regOut);
}
Any ideas/clues?
Thanks.
|