![]() ZBasic Language Reference
85
ZBasic Microcontrollers
Dim persVar as Persistent Integer Based &H300
Dim progVar as ProgMem Single Based &H1000
BasicX Compatibility Note
Based variables are not available in BasicX compatibility mode.
3.22 Based Procedures
Like based variables, based procedures are a powerful tool intended to be used by advanced
programmers who fully understand their nuances. No actual code space is consumed by a based
procedure. Rather, declaring a based procedure simply tells the compiler how to generate an invocation
of the procedure once its address is known.
The syntax for declaring a based subroutine or based function is shown below.
Declare Sub <name> ( [<parameter-list>] ) Based <addr-expr>
Declare Function <name> ( [<parameter-list>] ) As <type> Based <addr-expr>
As with based variables, the <addr-expr> giving the address of the procedure to be invoked must have
an integral type and can be either constant or non-constant (i.e., computed at run time). The based
procedure declaration may be placed inside a subroutine or function in which case the declaration is
private to that routine. At the module level, the Declare keyword may be proceeded by Public or
Private and if neither is specified, the declaration will be public by default.
When using a based procedure, you must be very careful to be certain that the declaration matches the
actual procedure that exists at the address that is specified. If the address given is not the beginning of a
procedure that is the same type and has the same number and type of parameters, the result is
unpredictable but will likely cause your program to malfunction.
BasicX Compatibility Note
Based procedures are not available in BasicX compatibility mode.
One issue that arises in conjunction with based procedures is that the compilers algorithm for estimating
the stack use of each procedure cannot determine how much stack space is used by the set of actual
procedures that might be invoked by way of a based procedure. Consequently, the minimum task stack
size will be listed as indeterminate for any task that invokes a procedure that, directly or indirectly, uses
a based procedure.
As a solution to this problem, a special mechanism is provided for you to provide the compiler the set of
procedures that might be called via a based procedure. Assuming that a complete set of called
procedures is provided for each based procedure, the compiler will provide an accurate estimate of
minimum task stack size. The syntax for providing call target information is shown below.
#pragma CallTargets ( <based-procedure> : <procedure-list> )
The <procedure-list> element is a comma-separated list of procedure names and/or names of
initialized ProgMem data items. In the latter case, it is assumed that the ProgMem data item is an array
of procedure addresses.
|