Statement: pop[var – Rockwell Automation 1771-DB Basic Module User Manual - Series A User Manual

Page 76

Advertising
background image

Operating Functions

Chapter 5

5–39

Mode: COMMAND AND/OR RUN
TYPE: ASSIGNMENT

The value on top of the ARGUMENT STACK is assigned to the variable
following the POP statement and the ARGUMENT STACK is “POPed”
(i.e. incremented by 6). You can place values on the stack using either the
PUSH statement or assembly language CALLS.

Important: If a POP statement executes and no number is on the
ARGUMENT STACK, an A-STACK ERROR occurs.

Variations: You can pop more than one variable off the ARGUMENT stack
with a single POP statement. The variables are followed by a comma (i.e.
POP [var],[var], ............ [var]).

Examples:

See PUSH statement above (section 5.4.25).

You can use the PUSH and POP statements to minimize GLOBAL variable
problems. These are caused by the “main” program and all subroutines
used by the main program using the same variable names (i.e. GLOBAL
VARIABLES). If you cannot use the same variables in a subroutine as in
the main program you can re–assign a number of variables (i.e. A=Q)
before a GOSUB statement is executed. If you reserve some variable
names just for subroutines (S1, S2) and pass variables on the stack as
shown in the previous example, you can avoid any GLOBAL variable
problems in the BASIC Module.

The PUSH and POP statements accept dimensioned variables A(4) and
S1(12) as well as scalar variables. This is useful when large amounts of
data must be PUSHed or POPed when using CALL routines.

Example:

u40 FOR I=1 TO 64

u50 PUSH I

u60 CALL 10

u70 POP A(I)

u80 NEXT I

5.4.26
Statement: POP[var]

Advertising