RTC
®
5 PC Interface Board
Rev. 1.9 e
6 Developing User Applications
76
innovators for industry
6.5 Structured Programming
The RTC
®
5 command set supports structured
programming and output of list commands via
numerous ways to define subroutines and character
sets, as well as several list commands for controlling
program flow. These are described below.
6.5.1 Subroutines
As list-command sequences, subroutines can theoret-
ically be located in any part of the list memory. Pref-
erably, they should be written to a list buffer’s upper
portion (see
"Protected Buffer Area", page 69
boundaries should not run through a subroutine.
Subroutines must be terminated with a
command.
Indexed as well as non-indexed subroutines can be
defined (non-indexed subroutines could already be
defined in the RTC
®
5’s predecessor boards).
Non-Indexed Subroutines
As with normal list-command sequences, non-
indexed subroutines are loaded into a list buffer
(“List 1” or “List 2”) via list-loading commands (see
). Each subroutine must be
terminated with a
command and can be
invoked by calling the
command with a
parameter specifying the absolute memory address.
After the subroutine (including the terminating
command) has been processed, execution
continues with the command that follows the
subroutine-call command.
Nested calls are also possible, to a depth of 63.
Notes
• Though non-indexed subroutines cannot be
written to the protected buffer area (“List 3”),
they can be subsequently assigned protection
(also see
"Subsequent Protection and Conversion
of Non-Indexed Subroutines", page 78
).
Therefore, the subroutine can be subsequently
referenced via the command
(only) if its starting address is known. Prior to
loading a non-indexed subroutine into the list
buffer area (“List 1” or “List 2”), you should
therefore always read out the start address via
the command
.
Indexed Subroutines
The RTC
®
5 lets you define not only non-indexed
subroutines, but also indexed subroutines. The
command assigns a desired index to a
subroutine defined via subsequent list commands,
and loads the subroutine into the protected buffer
area (“List 3”). Indexed subroutines must be termi-
nated with a
command (otherwise they
won’t be stored) and can be invoked by calling the
command with a parameter specifying the
index.
Nested calls are also possible, up to a depth of 63.
Up to 1024 subroutines can be stored. Memory
management of the indexed subroutines is auto-
matic. The RTC
®
5 stores each indexed subroutine’s
index, corresponding memory address (start
position) and number of list commands in an internal
management table. User management of indexes for
indexed subroutines is described in the section
Management and Defragmentation", page 79
.
The memory address of an indexed subroutine can be
queried via
. This allows invocation
of the indexed subroutine as if it were a non-indexed
subroutine by supplying the absolute memory
address.
An indexed subroutine will only be stored via the
command when the following conditions
are fulfilled:
• If, prior to loading, configuration of “List 1” and
“List 2” resulted in a protected buffer area
(“List 3”) of sufficient size. For example, if all
memory is assigned to one or both lists, then no
indexed subroutines can be stored. The command
, if called after a
or similar command), can be used for
querying the amount of still-available memory in
the protected buffer area.
• If the indexed subroutine was terminated with a
command.
• If list_return is preceded by no other command
for positioning the input pointer (e.g. another
command,
).
• If the index is within the valid range (0 … 1023).
After the
command, the input pointer
becomes invalid and any subsequent list commands
will no longer be stored.