|
|
|
|
|
Subroutines
|
|
Often, a program contains a certain series of instructions that are executed
several times in several places in a program. Or a program requires a set
of instructions that are included in another program. These instructions can
be executed by a program as a subroutine. A subroutine is selected and
executed in a program by the XEQ (execute)
function. Using XEQ , you can select either ALPHA
labeled or numeric labeled subroutines.
|
|
In a program, XEQ transfers execution to the program
label specified by the XEQ function. After the
subroutine has been executed, and the running program executes an
END of RTN , execution is
transferred back to the main program. Execution then continues with the next
instruction after the XEQ and sequentially down
through the program. Note that a GTO merely
transfers execution to the specified label but does not return execution to the
main program. The illustration below should make clear the distinction between
GTO and XEQ .
|
|
|
Branch
|
|
Subroutine
|
|
|
LBLTTEST
|
|
LBL 01
|
|
LBLTTEST
|
|
LBL 01
|
|
|
|
|
|
|
|
|
|
|
|
GTO 01
|
|
|
XEQ 01
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RTN
|
|
RTN
|
|
|
RTN
|
RTN
|
|
|
|
|
|
Execution
|
|
Execution
|
|
|
|
|
|
|
stops here.
|
|
stops here.
|
|
|
|
|
|
In the illustration of a branch, on the left, if you ran program TEST, the program
would execute instructions sequentially donwward through program memory. When it
encounters the GTO 01 instruction, it would then search
for the next LBL 01 in the program, and continue execution
until it encountered an END or
RTN . At that point, execution would halt.
|
|
However, if you ran the TEST program on the right, the program would execute
instructions sequentially downward through program memory until it encountered
the XEQ 01 instruction. It would then search for the next
LBL 01 in the program, and than continue execution there.
When it encountered an RTN , program execution would be
transferred again, this time back to the main program. It would then resume with
the next instruction after the XEQ 01.
|
|
|
|