I was able to get the CPU for the most part to load in, but when I pass in the tst file into the system, it is showing comparison errors while using the A instruction when the output seems to be working just fine. I never had issues with the course so far and I honestly didn’t have trouble with any other part of the build until now. However, I still feel like some of the specifications were a little vague and I had to make a lot of assumptions on how to structure the bits.
Here is the HDL for my cpu
IN inM[16], // M value input (M = contents of RAM[A])
instruction[16], // Instruction for execution
reset; // Signals whether to re-start the current
// program (reset==1) or continue executing
// the current program (reset==0).
OUT outM[16], // M value output
addressM[15], // Address in data memory (of M)
pc[15]; // address of next instruction
//// Replace this comment with your code.
Not(in=instruction[15], out=isAinstruct);
Mux16(a=ALUOUT, b=instruction, sel=isAinstruct, out=mux1out);
Xor(a=chooseA, b=isAinstruct, out=Aload);
ARegister(in=mux1out, load= chooseA, out=Areg);
DRegister(in=ALUOUT, load= Aload, out= Dreg);
Mux16(a=Areg, b=inM, sel=chooseM, out=mux2out);
ALU(x=Dreg,y=mux2out,zx=instruction[11],nx=instruction[10],zy=instruction[9],ny=instruction[8],f=instruction[7],no=instruction[6],out=ALUOUT, zr=zero, ng=neg);
DMux8Way(in = instruction[15], sel=instruction[3..5], a=noDest,b=selM,c=selD,d=selMD,e=selA,f=selAM,g=selAD,h=selALL);
Or8Way(in[0]=selM, in[1]=selMD, in[2]=selAM, in[3]=selALL, out=chooseM);
Or8Way(in[0]=selD, in[1]=selMD, in[2]=selAD, in[3]=selALL, out=chooseD);
Or8Way(in[0]=selA, in[1]=selAM, in[2]=selAD, in[3]=selALL, out=chooseA);
Mux16(a=inM, b=ALUOUT, sel=chooseM, out=outM);
And(a=instruction[15], b=instruction[3], out=writeM);
DMux8Way(in=instruction[15], sel=instruction[0..2], a=nojmp, b=JGT, c=JEQ, d=JGE, e=JLT, f=JNE, g=JLE, h=JMP);
Not(in=zero, out=notZero);
And(a=notZero, b=notNeg, out=pos);
And(a=JGT, b=pos, out=jmp1);
And(a=JEQ, b=zero, out=jmp2);
And(a=JGE, b=notNeg, out=jmp3);
And(a=JLT, b=neg, out = jmp4);
And(a=JNE, b=notZero, out=jmp5);
And(a=JLE, b=notPos, out=jmp6);
Or8Way(in[0]=jmp1,in[1]=jmp2,in[2]=jmp3,in[3]=jmp4,in[4]=jmp5,in[5]=jmp6,in[6]=JMP,out=JUMP);
PC(in=Areg, inc=true, load=JUMP, reset=reset, out[0..14]=pc);
<code>CHIP CPU {
IN inM[16], // M value input (M = contents of RAM[A])
instruction[16], // Instruction for execution
reset; // Signals whether to re-start the current
// program (reset==1) or continue executing
// the current program (reset==0).
OUT outM[16], // M value output
writeM, // Write to M?
addressM[15], // Address in data memory (of M)
pc[15]; // address of next instruction
PARTS:
//// Replace this comment with your code.
Not(in=instruction[15], out=isAinstruct);
Mux16(a=ALUOUT, b=instruction, sel=isAinstruct, out=mux1out);
Xor(a=chooseA, b=isAinstruct, out=Aload);
ARegister(in=mux1out, load= chooseA, out=Areg);
DRegister(in=ALUOUT, load= Aload, out= Dreg);
Mux16(a=Areg, b=inM, sel=chooseM, out=mux2out);
ALU(x=Dreg,y=mux2out,zx=instruction[11],nx=instruction[10],zy=instruction[9],ny=instruction[8],f=instruction[7],no=instruction[6],out=ALUOUT, zr=zero, ng=neg);
//destination bits
DMux8Way(in = instruction[15], sel=instruction[3..5], a=noDest,b=selM,c=selD,d=selMD,e=selA,f=selAM,g=selAD,h=selALL);
Or8Way(in[0]=selM, in[1]=selMD, in[2]=selAM, in[3]=selALL, out=chooseM);
Or8Way(in[0]=selD, in[1]=selMD, in[2]=selAD, in[3]=selALL, out=chooseD);
Or8Way(in[0]=selA, in[1]=selAM, in[2]=selAD, in[3]=selALL, out=chooseA);
Mux16(a=inM, b=ALUOUT, sel=chooseM, out=outM);
And(a=instruction[15], b=instruction[3], out=writeM);
//Jmp bits and pc
DMux8Way(in=instruction[15], sel=instruction[0..2], a=nojmp, b=JGT, c=JEQ, d=JGE, e=JLT, f=JNE, g=JLE, h=JMP);
Not(in=zero, out=notZero);
Not(in=neg, out=notNeg);
And(a=notZero, b=notNeg, out=pos);
Not(in=pos, out=notPos);
And(a=JGT, b=pos, out=jmp1);
And(a=JEQ, b=zero, out=jmp2);
And(a=JGE, b=notNeg, out=jmp3);
And(a=JLT, b=neg, out = jmp4);
And(a=JNE, b=notZero, out=jmp5);
And(a=JLE, b=notPos, out=jmp6);
Or8Way(in[0]=jmp1,in[1]=jmp2,in[2]=jmp3,in[3]=jmp4,in[4]=jmp5,in[5]=jmp6,in[6]=JMP,out=JUMP);
PC(in=Areg, inc=true, load=JUMP, reset=reset, out[0..14]=pc);
//jmp bits
}
</code>
CHIP CPU {
IN inM[16], // M value input (M = contents of RAM[A])
instruction[16], // Instruction for execution
reset; // Signals whether to re-start the current
// program (reset==1) or continue executing
// the current program (reset==0).
OUT outM[16], // M value output
writeM, // Write to M?
addressM[15], // Address in data memory (of M)
pc[15]; // address of next instruction
PARTS:
//// Replace this comment with your code.
Not(in=instruction[15], out=isAinstruct);
Mux16(a=ALUOUT, b=instruction, sel=isAinstruct, out=mux1out);
Xor(a=chooseA, b=isAinstruct, out=Aload);
ARegister(in=mux1out, load= chooseA, out=Areg);
DRegister(in=ALUOUT, load= Aload, out= Dreg);
Mux16(a=Areg, b=inM, sel=chooseM, out=mux2out);
ALU(x=Dreg,y=mux2out,zx=instruction[11],nx=instruction[10],zy=instruction[9],ny=instruction[8],f=instruction[7],no=instruction[6],out=ALUOUT, zr=zero, ng=neg);
//destination bits
DMux8Way(in = instruction[15], sel=instruction[3..5], a=noDest,b=selM,c=selD,d=selMD,e=selA,f=selAM,g=selAD,h=selALL);
Or8Way(in[0]=selM, in[1]=selMD, in[2]=selAM, in[3]=selALL, out=chooseM);
Or8Way(in[0]=selD, in[1]=selMD, in[2]=selAD, in[3]=selALL, out=chooseD);
Or8Way(in[0]=selA, in[1]=selAM, in[2]=selAD, in[3]=selALL, out=chooseA);
Mux16(a=inM, b=ALUOUT, sel=chooseM, out=outM);
And(a=instruction[15], b=instruction[3], out=writeM);
//Jmp bits and pc
DMux8Way(in=instruction[15], sel=instruction[0..2], a=nojmp, b=JGT, c=JEQ, d=JGE, e=JLT, f=JNE, g=JLE, h=JMP);
Not(in=zero, out=notZero);
Not(in=neg, out=notNeg);
And(a=notZero, b=notNeg, out=pos);
Not(in=pos, out=notPos);
And(a=JGT, b=pos, out=jmp1);
And(a=JEQ, b=zero, out=jmp2);
And(a=JGE, b=notNeg, out=jmp3);
And(a=JLT, b=neg, out = jmp4);
And(a=JNE, b=notZero, out=jmp5);
And(a=JLE, b=notPos, out=jmp6);
Or8Way(in[0]=jmp1,in[1]=jmp2,in[2]=jmp3,in[3]=jmp4,in[4]=jmp5,in[5]=jmp6,in[6]=JMP,out=JUMP);
PC(in=Areg, inc=true, load=JUMP, reset=reset, out[0..14]=pc);
//jmp bits
}
I tried checking if the issue was related to the output of one of the mux gates and the A register wasn’t supposed to take in the value; however I realized this wasn’t the case after rewatching the video.