The problem is that for the
while, the Jack compiler generates the following code:
label WHILE_EXP0
push constant 1
not
if-goto WHILE_END0
// code for the body
goto WHILE_EXP0
label WHILE_END0
The problem is, that
not is a bitwise negation, not logical one. So, it will replace the 1 at the top of the stack with 1111111111111110, which is different than 0 so the
if-goto will not jump. The code generated for
if doesn't use the negation, even though the book suggests it's the way to compile it, hence the difference.
bupjae wrote
I have to debug ~1hr why my Math.jack is not working during Project 12 because of this :(
This is not a waste of time! You learned a lot in that 1 hour.