bubkas22 wrote
StackTest: 266 lines
Why is my StackTest so freaking long? Am I supposed to be doing some sort of clever optimization at this stage?
Your math is good for an approximate minimum. Your 266 line result is certainly good enough. The difference is that the StackTest.vm file has been improved to cover more test cases.
Keep in mind that for Nand2Tetris the emphasis is not on optimization; it's best to get things working and continue working through the course. You can come back later to do more optimization. (I think I just saw a way to reduce my comparison subroutines by 1 word each. Not worth doing, but it will bug me until I go look at it!)
If you want to compare your code generation to the numbers in other posts on this thread, you'll need to use this VM file:
// OLD VERSION of StackTest.vm
push constant 17
push constant 17
eq
push constant 892
push constant 891
lt
push constant 32767
push constant 32766
gt
push constant 56
push constant 31
push constant 53
add
push constant 112
sub
neg
and
push constant 82
or
(This old version only tests 1 of 3 cases of each comparison and doesn't test 'not'.)
--Mark