 |
Returning Values Through Variables |
As mentioned in the previous section, returning a value from ASM program on a similar
way like TI-Basic functions return values causes problems with AMS 2.xx. Therefore,
another way for returning values (which works well unconditionally) was introduced.
This method will be ilustrated using a concrete example. Look the following
modified "Folder" program given in the previous section (called "Folder List"):
// Write the variables in a folder into a list variable
#define RETURN_VALUE dirlist
#define USE_TI89
#define USE_TI92PLUS
#define USE_V200
#include <args.h>
#include <estack.h>
#include <vat.h>
void _main(void)
{
ESI argptr = top_estack;
SYM_ENTRY *SymPtr = SymFindFirst (GetSymstrArg (argptr), 1);
push_END_TAG ();
while (SymPtr)
{
push_ANSI_string (SymPtr->name);
SymPtr = SymFindNext ();
}
push_LIST_TAG ();
}
The only difference between this program and the program in the previous section is in
the usage of the RETURN_VALUE
directive: in this example, it is followed
with a variable name (dirlist
in this example). If
RETURN_VALUE
is followed with a variable name (which must be a legal
TI-Basic variable name in lowercase), the last value pushed to the expression stack would
be stored in the TI-Basic variable with the given name. So, in this example, after execution
of the program, the result of the program (a folder list) will be stored in TI-Basic
variable called dirlist
(if such variable does not exist, it will be
created). See the previous section for more info about this example. I hope that this
explanation is clear enough, so more detailed explanation is not necessary.