Page 51 of 62
SBasic User's Manual SBasic Version 2.7 Page 51
Printed: December 5, 1999
You can also use the PULL() function to remove items from the data
stack. PULL() works exactly the same was as the POP() function; it is
simply a synonym for POP().
You can copy a value from within the data stack by using the PICK()
function. PICK() locates a specific item within the data, and returns
that value.
Example:
n = pick(2)
copies the third item in the data stack into N. The size of the data
stack does not change, and the value in the third item does not
change.
Note that the item on the top of the stack is item 0; the second item
is item 1. SBasic does not check to see how many items are actually
on the data stack. If you supply an argument to PICK() that is larger
than the current data stack, SBasic will return a bogus but legal
value.
You can alter a value within the data stack by using the PLACE
statement. PLACE stores a 16-bit value into a specified item in the
data stack.
Example:
PLACE 2, n
stores the value in N into the third item in the data stack. The
value in N does not change, and the size of the data stack does not
change.
SBasic does not test the actual size of the data stack before
executing the PLACE statement. Using PLACE to modify an item beyond
the actual data stack will corrupt that location in memory and could
crash your program.
You can combine PICK() and PLACE to create 16-bit variables local to a
section of code, such as a subroutine. For example:
foo:
do
place 0, pick(0) + 1 ' increment the item
loop while pick(0) < 5 ' loop until it hits 5
This code uses an item, already stored on the data stack by previous
code, as a local variable. Changes to this variable occur only in the
data stack, not in a DECLAREd variable.