Index | PAL Intro | Commands | Registers | Indices | Stack | Macros | Classes | Attributes | Errors
local/jmp - Modify local program pointer
Synopsis
Description
Indirect Addressing
Error Handling
Examples
See Also
Author
local/jmp &[.codeptr]
local/jsr &[.codeptr]local/jmp (#index)
local/jmp (#index, #offset)
local/jsr (#index)
local/jsr (#index, #offset)
In the first synopsis form, jumps (jmp) or branches (jsr) to codeptr, which is a read argument that must point to a code label.
Jumping modifies the local program pointer, to point to a new section of code within the local file.
Branching also modifies the local program pointer, but pushes the current program pointer onto the program stack first. Program execution resumes from the command following the local/jsr, when the branch returns using local/rtn.
In the second synopsis form, the local/jmp and local/jsr instructions can be used with indirect addressing to read the code pointer directly from the code address table in the PROSE binary.
This is similar to the reg/load instruction described in reg_load_table(5), where the index identifies which code address to read from the internal table, starting from 0. The first code label defined or referenced in the PAL source file will have been given an index number of 0. Use reg/index to convert a code label of choice to an index number.
The optional offset argument is a raw index number that is added to index before the final lookup is performed. This allows for a single call to reg/index to be followed by multiple local/jsr instructions, each identifying subsequent code addresses by incrementing the value of offset each time.
A runtime error occurs if the argument is not a code pointer, or if an index provided to the indirect addressing syntax is out of bounds.
The following example uses the code address table to branch to a number of local routines in order. This is a more efficient example than those found in the reg_load_table(5) man page.
local/jmp &[.routine] Jumps to .routine. local/jsr &[.subroutine] Branches to .subroutine. Program execution will resume from the next command when the subroutine returns.
.sub1 obj/dump [Running .sub1] local/rtn
.sub2 obj/dump [Running .sub2] local/rtn
.sub3 obj/dump [Running .sub3] local/rtn
.main % Read table index for .sub1 reg/index P0, &[.sub1]
% Call each address in turn local/jsr (P0, #0) local/jsr (P0, #1) local/jsr (P0, #2) func/rtn
pal_commands(5), local_rtn(5), reg_load_table(5), reg_index(5),
PROSE Assembly Language at prose.sourceforge.net.
Copyright (c) 2002-2008 Mark R. Bannister <cambridge@users.sourceforge.net>.
This is free software and can be downloaded from prose.sourceforge.net; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
PAL 1.0 | local_jmp (5) | 5 December 2008 |