Possible discrepency

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

Possible discrepency

pawdwanlearner
I am looking at the convert to bin code and my compiler so far so good until i reach this vm code. Ill try to make it ease

jack code
let loop = true;  

vm code produced by supplied compiler
push constant 0
not
pop local 2

my vm code for true
push constant 1
neg
pop local 2

excerpt from book on constant values chapter 11 under constants under standard mapping
sorry i have the e-book no page numbers

Null and false are mapped to the constant 0
true is mapped to the constant -1 which is obtained by
pushing the constant 1 followed by neg

so my question is am i doing some thing wrong or is there another problem here
Reply | Threaded
Open this post in threaded view
|

Re: Possible discrepency

cadet1620
Administrator
Your code is OK.

not(0) and -(1) are two different ways to make the same value.

VM not command is bitwise binary not, so:
~ 0000000000000000 = 1111111111111111 = -1 = true

--Mark