MathTest.tst fails even with provided OS .vm files

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

MathTest.tst fails even with provided OS .vm files

This post was updated on .
After I finished implementing Math.jack, I copied all of the provided OS .vm files into the MathTest directory, and compiled my Math.jack file, replacing the provided Math.vm file with my own.

Then I loaded the provided MathTest.tst file, and ran it in the VM EMulator. I noticed that the output had all zeros in every register, and couldn't figure out how to debug it. Eventually I realized that it was failing because it wouldn't finish execution within the 1000000 vmsteps allotted within the provided MathTest.tst.

This indicated to me that I had an inefficient implementation of the algorithm, or a simple bug, but after some time I couldn't figure it out. Eventually I replaced my Math.jack and Math.vm files with the Math.vm file provided to us (in the tools/OS directory). Surely now it has to be able to complete execution, but surprisingly it did not.

I double, and triple, checked that I was using the provided Math.vm file and not my own version.

I tried setting the number of vmsteps to 2000000, and it worked.

I also tried keeping the number of vm steps at 1000000, and instead removing all .vm files, forcing the VM Emulator to use the built-in .java implementation of the OS. That worked as well.

The instructions however clearly state to use the provided OS .vm files, and replace only the .vm file that you're currently working on.

It seems unlikely that they would have set the number of vm steps at 1000000, without a good reason, so it's really weird to me that it fails to execute, even when using only the provided OS .vm files. It's even weirder to me that I can't find a post in this forum where anyone else had the same issue, since we're working with the same files. It probably means I'm doing something wrong, but I can't figure out what. All I'm doing is using only the provided .vm files and .tst file (including the provided Math.vm file), and clicking run. It only finishes when I manually increase the number of vm steps in the .tst file.

Has anyone else had this issue? Any suggestions on how to address it without manually changing the number of vm steps?

* EDIT: To be specific, it takes exactly 1117931 vm steps for the execution to complete successfully using only the provided OS .vm files (including the provided Math.vm file). An less than that, and it fails. Would be curious to know if anyone else has the same results.
Reply | Threaded
Open this post in threaded view

Re: MathTest.tst fails even with provided OS .vm files

Dear Gnodar,

I am very grateful for your remarks. It was very helpful to me in diagnosing my own similar problem.
In my case, the supplied math.vm file worked fine within the 1000000 steps but my own math.vm implementation kept failing with the error message: "comparison failure at line 2".

The thing I previously found surprising but now fully understand was that when I run my own math implementation in the VM emulator without the test script (with animation disabled) and later inspect the specified RAM locations, I get the correct answer when I do a manual comparison with the MathTest.cmp file.

Thanks to your remarks, I adjusted the steps in the MathTest.tst script to 2000000 and now my implementation works fine.

Many thanks!