Start Back Next End
  
ZBasic Language Reference
54
ZBasic Microcontrollers
The table below gives the number of bytes of stack space required to pass different variable types using
the two passing methods.  This table applies only to VM mode devices.  For native mode devices,
parameters are passed in registers in most cases and, therefore, require no stack space.
Stack Usage by Parameter Type and Passing Method
Actual Parameter Type
Pass By Value
Pass By Reference
Boolean, Byte
1
2
Bit, Nibble
1
Integer, UnsignedInteger, Enum
2
2
Long, UnsignedLong, Single
4
2
String¹, structure
2
2
Array, any type
n/a
2
Notes:
¹ Persistent strings, Program Memory strings and strings returned by functions all require 4 bytes of
temporary data space (local to the caller) plus the 2-byte reference when passed to a routine
other than a System Library routine.
² Sub-byte types like Bit and Nibble may only be passed by reference if they are byte aligned.  See
Section 3.24.1 for details.
2.15 Program and Data Item Properties
Most data items, whether located in RAM, Persistent Memory or Program Memory have an associated
property called DataAddress that evaluates to the address of the data item.  The DataAddress property is
applied to a data item by appending it to the data item’s name with a period separating them as illustrated
by the example below.
Example
Dim b as Byte
Dim addr as UnsignedInteger
Sub Main()
  addr = b.DataAddress
End Sub
The DataAddress property can be applied to arrays and structures as well.  When used with arrays it is
best to append it after the array indices, if any.  For most data items, the type of the DataAddress
property is UnsignedInteger.  However, for compatibility with GetProgMem() and other routines related
to Program Memory, the type of the DataAddress property for Program Memory data items is Long.
Along similar lines, subroutines and functions have an associated property called CodeAddress whose
type is Long.  The CodeAddress property is employed in a similar manner as the DataAddress property is
as shown by the example below.  Of course, use of the CodeAddress property of a subroutine is not
limited to the code in the subroutine itself.  It can be applied to any subroutine or function that is visible to
the code.  In short, if you can invoke the subroutine or function, you can also get its address via the
CodeAddress property.
Example
Dim addr as Long
Sub Main()
  addr = Main.CodeAddress
End Sub
Previous page Top Next page