Although it has many advanced features, at heart PASM is an assembly language. All flow control in PASM—as in most assembly languages—is done with branches and jumps.
Branch instructions transfer control to a relative offset from the
current instruction. The rightmost argument to every branch opcode is
a label, which the assembler converts to the integer value of the
offset. You can also branch on a literal integer value, but
there’s rarely any need to do so. The simplest
branch instruction is
branch L1 # branch 4 print "skipped\n" L1: print "after branch\n" end
This example unconditionally branches to the location of the label
L1, skipping over the first
Jump instructions transfer control to an absolute address. The
jump opcode doesn’t calculate an
address from a label, so it’s used together with
et_addr I0, L1 jump I0 print "skipped\n" end L1: print "after jump\n" end
opcode takes a label or an integer
offset and returns an absolute address.
You’ve probably noticed the
opcode as the last statement in many
examples above. This terminates the execution of the current bytecode
segment. Terminating the main bytecode segment (the first one) stops
the interpreter. Without the
execution just falls off the end of the segment, with a good chance
of crashing the interpreter.
Unconditional jumps and branches aren’t really enough for flow control. What you need to implement the control structures ...