Zamar wrote
I've run into an issue with the sub command while running the StackTest.vm and BasicTest.vm files
StackTest.vm compares successfully if I use "M = D - M" but fails on BasicTest.vm whereas BasicTest.vm compares successfully if I use "M = M - D" but fails on StackTest.vm
Which is the correct one?
If you haven't already, look at the .vm files for the two tests.
The version of 'sub' that works in StackTest is probably the correct one for several reasons:
1) You thought about what 'sub' had to do and wrote the code to do what it needed to do.
2) BasicTest assumes that the VM commands tested in the StackArithmetic tests are working correctly, and adds more VM commands to be tested. It is far more likely that a problem with the additional VM commands is causing the failure than a problem with the 'sub' commands it uses.
3) A = B-A is a "reverse subtraction". This is a rarely used construction and whenever I see it in other people's code when I'm debugging I look at it very suspiciously. I find that in the vast majority of cases the actual usage is A= -(A-B), and in that case the code is easier to understand if it's written that way.
--Mark