Confused about CPU-external.cmp

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Confused about CPU-external.cmp

gnb03
Hi,

So I was working through CPU-external.cmp by hand so I could compare what I was getting from my own CPU to what I should be getting. I was going through the assembly language provided in the comments of the file, but I found something that did not make sense.

Following line 12 of the assembly, I believe that the CPU should jump to line 14(I expected the D-register to equal -1 at time when the JLT command is given). Thus, the CPU should skip line 13(@999). However in the compare file, the CPU clearly accepts @999 as you can see that ‘addressM’ is set to 999 at time 13. At the same time in the compare file, the PC jumps from 11 to 14. How can the CPU jump from 11 to 14 while taking the command from line 13?

I have copied the assembly from the comments of the CMP file and pasted them below. I have also added line numbers.

1 @12345
2 D=A
3 @23456
4 D=A-D
5 @1000
6 M=D
7 @1001
8 MD=D-1
9 @1000
10 D=D-M
11 @14
12 D;JLT
13 @999
14 A=A+1
Reply | Threaded
Open this post in threaded view
|

Re: Confused about CPU-external.cmp

cadet1620
Administrator
You should be looking at CPU.tst/.cmp so that you can see the current D register values. The -external tests are for people who are not using DRegister in their CPU.

Test setups are strange. Because there is no RAM or ROM involved, each individual instruction test sets input values for 'instruction' and 'inM'. The PC does not affect the sequence of instructions fed to the CPU by the test, nor does the A register affect what the inM value is.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Confused about CPU-external.cmp

throwinshapes
This post was updated on .
Should I be concerned if my implementation of CPU is passing CPU.tst, but failing CPU-external.tst?

I found this blurb on the website document for project 5 while researching this issue:
"6. The projects/05 folder contains a set of files whose names include the label “external”. These
test files are no longer in use, and will be removed from future versions of the Nand to Tetris
software suite. Therefore, you should ignore them."

The current download "Download the Nand2tetris Software Suite Version 2.6" from the website still includes the -external files.


EDIT: I found later my CPU was failing during ComputerRect.tst. Diagnosing this, I found my CPU implementation was allowing load to be enabled on the D register regardless of whether the instruction was a A or D type. I guess CPU-external.tst contains a test that finds this error, while CPU.tst does not.
Reply | Threaded
Open this post in threaded view
|

Re: Confused about CPU-external.cmp

WBahn
Administrator
It has been years since I've worked with those scripts, but it appears that the only difference is that the -external ones output the contents of the A, D, and PC registers. These scripts may require that your implementation use the special built-in parts and not the ones you built (I'm not positive about that, however).

If your code is erroneously changing the D register, this script will likely pick up on that better than the other script does.
Reply | Threaded
Open this post in threaded view
|

Re: Confused about CPU-external.cmp

throwinshapes
Thanks for the reply.

cpu-external.tst did work with the ARegister and DRegister built in chips still in the .hdl file. (And passed the compare after fixing the previously mentioned issue).