The instruction that is failing is 1110110111100000. Look in CPU.tst to decode the instruction.
set instruction %B1110110111100000, // A=A+1
The previous instruction, @999, set A=999, so this instruction should set it to 1000.
The A register is being loaded with a value that appears to be unrelated to the ALU output.
Fix this one problem, and your CPU will pass.
// if this instruction is a-instruction
//if this instruction is c-instruction
Making aInst and cInst is a very good idea. You should move this code to the beginning of PARTS: because it is very important. Then you should use aInst and cInst throughout the remaining code instead if instruction. This will make the code more understandable and help prevent errors like this one.
The instruction where you are failing, A=A+1, is the first C-command with the A Register destination bit set.
Check the logic for A Register's load pin and the select input on the Mux16 that connects to the A Register input.
One thing that you can do is single step the simulator and stop one line before the failure so that you are looking at the erroneous inputs to the A register just before the erroneous instruction executes. Trace the logic back to figure out where the error is.
If you don't see the problem, post the .out and .cmp files where the failure is. The specific wrong values will give a clue as to what is wrong.
This is an A=A+1 instruction. The A register should have been loaded with 1000, but instead it was loaded with 28128.
This is an interesting number: 28128 = 110110111100000 binary, which is the low 15 bits of the instruction (addre[ssM] is the low 15 bits of the A Register). This means that the "sel" input on the A Register input Mux16 is probably connected to the wrong thing.
Since this Mux16 controls whether the ALU output (for C instructions) or CPU instruction input (for A instructions) goes to A, it needs to be controlled by the "instruction" bit that differentiates the two types of instructions.
If I understand correctly, it means that the 'sel' logic of the first Mux is wrong.
But all the 'd' s are 0 so there is no jump and the Mux should choose the instruction and not the feed from the ALU. What is wrong is this logic?
There is a 'd':
I do not understand what you mean about jump. This mux has nothing to do with jumps.
Using the 'd' bits to control this mux will be a problem because those bits can be set in a-instructions, too. You should only select the instruction to go to the A register for a-instructions. In all other cases (c-instructions since there are only two types of instructions 8-), select the ALU output.