Rockwell Automation 1771-DB BASIC MODULE User Manual

Page 180

Advertising
background image

Chapter
Statements

11

11 -28

Use the POP statement to remove values from the BASIC module
argument stack. The value at the top of the argument stack is assigned to
the variable following the POP statement and the argument stack is popped
(decrements by 6 bytes). You can place values in the stack using the
PUSH statement (page 11 -30).

Important: If a POP statement executes and no number is in the argument
stack, an A-stack error occurs and the BASIC module enters Command
mode.

You can pop more than one variable off the argument stack using a single
POP statement with multiple variables (var, var, var). You must follow
each expression with a comma. The PUSH and POP statements accept
dimensioned variables A(4) and S1(12) as well as scalar variables. This is
useful when using call routines (see Chapters 12 and 13) in which large
amounts of data must be pushed or popped.

You can use the PUSH and POP statements to minimize GLOBAL variable
problems. These are caused by the main program and main program
subroutines using the same variable names. If you cannot use the same
variables in a subroutine as in the main program, you can re-assign a
number of variables (example: A=Q) before a GOSUB statement (page
11 -13) is executed. If you reserve some variable names just for
subroutines (S1, S2) and pass variables on the stack, you can avoid
GLOBAL variable problems in the BASIC module.

Syntax

POP

var, var,.......var

Example

>1 REM EXAMPLE PROGRAM

>40 FOR I=1 TO 64

>50 PUSH I

>60 CALL 10

>70 POP A(I)

>80 NEXT I

POP

Chapter

Advertising