nand2tetris.zip > projects/04/mult/Mult.tst

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

nand2tetris.zip > projects/04/mult/Mult.tst

mindfields
The CPU Emulator is giving me the error: "Comparison failure at line 1"

The reason is that the .cmp file has the output of the whole 3 virtual registers: R0, R1 and R2 (accordingly RAM[0], RAM[1] and RAM[2]) but the .tst script is outputting only the R2 virtual register (RAM[2]).
I fixed the .tst script as follows:

line 9 (old):  output-list RAM[2]%D2.6.2;

line 9 (fixed): output-list RAM[0]%D2.6.2 RAM[1]%D2.6.2 RAM[2]%D2.6.2;

And it worked. I hope you can test, confirm and fix this bug and update the download archive from the Software section of the site - nand2tetris.zip
So new scholars won't get frustrated from errors in a .tst script. :)

Great Course BTW!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nand2tetris.zip > projects/04/mult/Mult.tst

cadet1620
Administrator
mindfields wrote
The CPU Emulator is giving me the error: "Comparison failure at line 1"
It's actually the mult.cmp file that's wrong.  RAM[0] and RAM[1] were intentionally removed from the test because a correct program is allowed to change them; only the multiplication product should be tested.

Correct mult.tst and mult.cmp files can be downloaded from this post.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nand2tetris.zip > projects/04/mult/Mult.tst

mindfields
My first program did change the RAM[0] or RAM[1] memory cells (R0 or R1 virtual registers) depending on which of them contains a smaller value. I did a quick test in order to minimize the number of loop repetitions. And it was using two more memory cells (pointer variables) in order to remember which one of the registers has a smaller value.

After the problem occured I changed the program to copy the values of R0 and R1 in those memory cells to achieve the same effect. And than I decided to change the .tst file so my output is in the same format as the .cmp file.

I was observing the trade offs happening in front of me. If I want less clock cycles I need to spend more memory for the optimizations. I was fascinated at this early stage and in such a small program to actually see the speed vs space problems a lot of low-level programs deal with. Well many modern CPUs (even the old ones) have more registers and instructions to choose from so at this point it is still not an issue, but anyway it was an interesting thing to observe. :)

Thank you for the quick replay!
Loading...