How can I choose a jump command for if-goto?

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

How can I choose a jump command for if-goto?

Jack ZRP
I put the "if-goto" Translated into
@SP
M=M-1
A=M
D=M
@funtionName$label
D;JLT
but it make mistake.
then I replace "JLT" with "JNE"
It comparison ended successfully!
We know JLT mean if out < 0 jump
JNE mean if out != 0 jump
if the top of the stack is -1(0xffff, true)
out < 0, so I think "JLT" can also work
Reply | Threaded
Open this post in threaded view
|

Re: How can I choose a jump command for if-goto?

cadet1620
Administrator
Jack ZRP wrote
I put the "if-goto" Translated into
...
@funtionName$label
D;JLT
but it make mistake.
then I replace "JLT" with "JNE"
It comparison ended successfully!
...
if the top of the stack is -1(0xffff, true)
out < 0, so I think "JLT" can also work
The VM specification in 8.3.1 says:

"if-goto label    This command effects a conditional goto operation. The stack’s
topmost value is popped; if the value is not zero, execution continues from the
location marked by the label; otherwise, execution continues from the next command
in the program. The jump destination must be located in the same function."

If the top of stack value is 123, for example, then if-goto must jump.  This is why JLT doesn't work.

--Mark