gs99 wrote
In CPU.tst, when the @1001 occurs, D=11111.
The next instruction is MD=D-1.
Doesn’t that mean “Subtract 1 from D; store result in M and D”?
CPU spec: "OUT outM[16], // M value output"
If I put these instructions in CPU.asm, and run in CPU Emulator, RAM 1001 is changed to 11110.
CPU.cmp calls for DRegister to be 11110 but outM to be 11109.
Why isn’t outM 11110?
This is an artifact of testing the CPU in isolation.
Time 7+ shows the state before the MD=D-1 instruction executes.
|time| inM | instruction |reset| outM |writeM |addre| pc |DRegiste|
|7+ | 0|1110001110011000| 0 | 11110| 1 | 1001| 7| 11110 |
Two things happen before the time 8 state is displayed.
1) The clock event occurs and the instruction executes; the
sequential logic updates.
2) The
combinatorial logic updates.
Since the instruction is being set by the test script, it does not change so the ALU is still computing D-1. The ALU output, 11109, appears on outM.
|time| inM | instruction |reset| outM |writeM |addre| pc |DRegiste|
|8 | 0|1110001110011000| 0 | 11109| 1 | 1001| 8| 11110 |
When the CPU is tested in the Computer environment, when the combinatorial logic updates, because the pc changed, the next instruction is decoded and its ALU control bits cause the ALU to compute whatever your CPU decodes for @1000. (Mine sets all control signals to 0, computing D&A resulting in a rather strange value.)
| time |PC[]|ARegister|DRegister| outM |RAM16K[1000]|RAM16K[1001]|
| 6+ | 7| 1001 | 11111 | 864 | 11111 | 0 |
| 7 | 7| 1001 | 11111 | 11110 | 11111 | 0 |
| 7+ | 8| 1001 | 11110 | 11110 | 11111 | 11110 |
| 8 | 8| 1001 | 11110 | 864 | 11111 | 11110 |
| 8+ | 9| 1000 | 11110 | 864 | 11111 | 11110 |
| 9 | 9| 1000 | 11110 | -1 | 11111 | 11110 |
Why the PC is 1/2 clock out of sync is a mystery I still need to investigate!
[Two posts cross in the night. Your latest just came in while I was typing this. I had just finished the same experiment that you did.]
--Mark