JUMP Instruction - craterdog-archives/js-bali-virtual-machine GitHub Wiki
The JUMP Instruction
The JUMP
instruction tells the processor to update the current address to point to a different
bytecode instruction. The resulting address depends on one of the following modifiers:
The operand contains the target address for the JUMP instruction in the range 0x001..0x7FF
,
or the value 0x000
if the target address is just the next instruction.
JUMP TO NEXT INSTRUCTION
This is a degenerate version of the JUMP
instruction. It simply moves on to the next
instruction. It is used when multiple labels would need to refer to the same address. The
bytecode for this instruction has the form:
[00000000][00000000] note: 00000000000 is not a legal address
The following pseudo-code defines this instruction:
context.address = context.address + 1
Example Context Before Execution
Example Context After Execution
JUMP TO label
The JUMP
instruction with no modifier performs an unconditional jump to the address at the
label operand. The bytecode for this instruction has the form:
[00000aaa][aaaaaaaa] where aaaaaaaaaaa is the address of the label
The following pseudo-code defines this instruction:
context.address = operand
Example Context Before Execution
Example Context After Execution
JUMP TO label ON EMPTY
The JUMP
instruction with an ON EMPTY
modifier performs the jump to the address at the
label operand if the component stack is empty.
The bytecode for this instruction has the form:
[00010aaa][aaaaaaaa] where aaaaaaaaaaa is the address of the label
The following pseudo-code defines this instruction:
if task.components.isEmpty() then {
context.address = operand
} else {
context.address = context.address + 1
}
Example Context Before Execution
Example Context After Execution
JUMP TO label ON NONE
The JUMP
instruction with an ON NONE
modifier performs the jump to the address at the
label operand if the component on top of the component stack is none
.
The bytecode for this instruction has the form:
[00001aaa][aaaaaaaa] where aaaaaaaaaaa is the address of the label
The following pseudo-code defines this instruction:
condition = task.components.pop()
if condition = none then {
context.address = operand
} else {
context.address = context.address + 1
}
Example Context Before Execution
Example Context After Execution
JUMP TO label ON FALSE
The JUMP
instruction with an ON FALSE
modifier performs the jump to the address at the
label operand if the toBoolean()
method for the component on top of the component stack
evaluates to false
. The bytecode for this instruction has the form:
[00011aaa][aaaaaaaa] where aaaaaaaaaaa is the address of the label
The following pseudo-code defines this instruction:
condition = task.components.pop()
if condition = false then {
context.address = operand
} else {
context.address = context.address + 1
}