Efficiency...

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

Efficiency...

aetesaki
If efficiency is paramount, how many instruction is the minimum for BasicTest.asm?

I hand-assembled BasicTest.vm successfully using 107 instructions, not including the end loop I added.
It wasn't easy, though. I really had to keep my ducks in the row. I found getting the math correctly most difficult, as the direction of calculation wasn't too well explained. I made the assumption that the VM used RPN, but obviously that was wrong
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency...

WBahn
Administrator
The math rules in Jack are deliberately ill-defined. There is NO defined precedence or associativity beyond the requirement that expressions in parentheses are evaluated first. Therefore an implementation is free to use whatever order of operations is convenient, which means that two perfectly valid implementations may produce different results. So your implementation may not produce the same results as the VM, but that doesn't make it wrong.

Jack code that does not fully utilize parens to force the proper evaluation of all expressions invokes undefined behavior.
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency...

aetesaki
WBahn wrote
The math rules in Jack are deliberately ill-defined. There is NO defined precedence or associativity beyond the requirement that expressions in parentheses are evaluated first. Therefore an implementation is free to use whatever order of operations is convenient, which means that two perfectly valid implementations may produce different results. So your implementation may not produce the same results as the VM, but that doesn't make it wrong.
Jack may not have a multi before addition rule, but this is the VM-code

Looking at how the VM emulator calculates subtraction, it's obvious which number on the stack takes presedens over the other. It calculates M[SP-2] - M[SP-1], storing the result in M[SP-2], which after updating SP is M[SP-1].

If you calculate M[SP-1] - M[SP-2], you get the wrong answer, and the output fails.
The fact that the Hack computer architecture are missing a vital instruction (D=M-D), doesn't make the assembling easier.
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency...

aetesaki
In reply to this post by aetesaki
Well, just hand-assembled PointerTest.vm too. 51 instructions, not including added end loop
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency...

WBahn
Administrator
In reply to this post by aetesaki
The VM language spec doesn't have multiplication at all. How a particular VM implements something that is not specified should not be relied upon. That's asking for trouble.

2nd Ed?
aetesaki wrote
Looking at how the VM emulator calculates subtraction, it's obvious which number on the stack takes presedens over the other. It calculates M[SP-2] - M[SP-1], storing the result in M[SP-2], which after updating SP is M[SP-1].

If you calculate M[SP-1] - M[SP-2], you get the wrong answer, and the output fails.
This has nothing to do with precedence or order of operations. The VM language spec explicitly specifies which value on the stack is the minuend and which is the subtrahend for the 'sub' command.
 
aetesaki wrote
The fact that the Hack computer architecture are missing a vital instruction (D=M-D), doesn't make the assembling easier.
What makes you think that? M-D is explicitly one of the 28 instructions that are specified. Review Figure 4.3 (1st Ed). Are you saying that it is now missing from the 2ed?
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency...

aetesaki
2.5, and I'm not going to debug it. If something doesn't work, I'll just work around it.
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency...

WBahn
Administrator
2.5 what? Not sure what you are referring to here.