User Guide

Table Of Contents
Command Syntax
Siemens Building Technologies, Inc. 3-53
100 C MAINLINE PROGRAM FOR LOGICAL FIRMWARE
110 C LEARNING HOW TO USE GOSUB, RETURN, AND
112 C $ARG COMMANDS.***
120
130 GOSUB 1010
...
...
...
300 GOSUB 2010 PT1, PT2
...
...
...
400 GOTO 3000
1000 C --SUBROUTINE 1
1001 C THIS SUBROUTINE ASSIGNS NUMBERS
1002 C TO PT1 AND PT2. IT THEN RETURNS
1004 C CONTROL TO THE MAIN PROGRAM.
1008 C
1010 PT1 = 10
1020 PT2 = 20
1030 RETURN
2000 C --SUBROUTINE 2
2001 C THIS SUBROUTINE PASSES THE VALUE OF
2002 C PT1 AND PT2 TO THEIR RESPECTIVE $ARG
2003 C POINTS. IT THEN ADDS ONE TO BOTH $ARG
2004 C POINTS AND RETURNS THE NEW VALUES TO
2005 C PT1 AND PT2.
2006 C
2010 $ARG1 = $ARG1 + 1
2020 $ARG2 = $ARG2 + 1
2030 RETURN
3000 C WHEN THE SUBROUTINE IS FINISHED
3002 C EXECUTING, THE PROGRAM RETURNS TO
3004 C MAINLINE CODE.
Figure 3-1. Example Program with Two Subroutines.
APOGEE PPCL User’s Manual
3-54 Siemens Building Technologies, Inc.
Multiple-Level Subroutines
The following example demonstrates the use of $ARGn variables
and point declarations used in multiple-level subroutines.
This example demonstrates a method for preserving the values of
$ARGn variables as program control is transferred among
subroutines. The example program contains a main line section of
program code and three subroutines. Refer to Figure 3-2 as you
follow the program flow sequence.
The program flow through one complete pass is as follows:
1. At line 1500, the GOSUB command transfers control to line 2030
and passes the value defined in PT1 to $ARG1 in the
subroutine.
2. While executing the first subroutine, the program encounters a
call to a second subroutine at line 2500.
Since the GOSUB command at line 2500 is defined within
another subroutine, this command must redefine $ARG1 in
order to preserve the value from the GOSUB command at
line 1500.
If $ARG1 is not redefined in the call to the second
subroutine, any value introduced in the second subroutine
replaces the value in $ARG1.
The new value introduced in the second subroutine (PT2 in
the example) is defined after the $ARG1 variable.
As the program works with the variables $ARG1 and PT2 in
the second subroutine, $ARG1 continues to represent the
value of PT1, while $ARG2 represents the value of PT2.
3. At line 3200, the second subroutine calls a third subroutine.
Sine the GOSUB command at line 3200 is defined within two
other subroutines, this command must redefine both $ARG1
and $ARG2 in order to preserve their values.
Note that $ARG1 and $ARG2 are placed in the same order
in which they were originally defined.
Line 3200 also defines a new point called PT3. Note that
PT3 is placed after the two $ARGn variables.