88 of 172
ZBasic Language Reference 81 ZX Microcontroller Family BasicX Compatibility Note Based procedures are not available in BasicX compatibility mode. One issue that arises in conjunction with based procedures is that the compiler’s 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. Example Dim procTbl as IntegerVectorData({ proc1.CodeAddress, proc2.CodeAddress }) Dim procAddr as UnsignedInteger Declare Sub myProc() Based procAddr #pragma CallTargets(myProc : procTbl, proc3.CodeAddress) If the CallTargets pragma occurs at the module level, it will be visible throughout the module. If it occurs within a procedure, it applies beginning at the line on which it occurs (overriding any CallTargets pragma at the module level for the same based procedure) through the end of the procedure or the next occurrence of a CallTargets pragma for the same based procedure. A special form of the CallTargets pragma, with no <procedure-list>, may be used to terminate the validity of an earlier occurring CallTargets pragma. This form is shown by example below. #pragma CallTargets(myProc) There is a special case where the compiler composes an implicit CallTargets list which may obviate the need for explicitly specifying the CallTargets. If a based procedure is defined where the base expression is a simple expression comprising an initialized ProgMem data item with an index, the compiler assumes that all of the elements of the ProgMem data item are call targets. 3.24 Sub-byte Types In addition to the fundamental data types described in Section 2.2, ZBasic also supports Bit and Nibble data types. These are referred to as sub-byte types because they occupy less than a whole byte – 1 bit and 4 bits, respectively. In certain circumstances, these types may help reduce the total RAM usage of an application. As compared to packing and unpacking bits in your source code, using these types will be more efficient in both execution time and code space. Bit and Nibble types may be used in most places where one of the fundamental data types may be used. You can define arrays of them, you can define Bit and Nibble constants, you can pass them as parameters and you can define functions returning these types. One limitation is that you cannot pass a Bit or Nibble variable to a subroutine/function by reference unless the variable is byte-aligned (see further discussion below). This implies, of course, that you may not be able to pass an array of sub-byte types as a parameter since arrays are always passed by reference. The reason for this limitation is that sub-byte variables do not necessarily begin on a byte boundary and there is no way for the called routine to know what the alignment might be. One way to work around this limitation is to define an integral-byte