Positron Compiler Documentation

Stack Declares.

Source: Positron16 Compiler User Manual, PDF page 428

Declare Stack_Size = 20 to n (in words) The compiler sets the default size of the microcontroller’s stack to 60 words (120 bytes). This can be increased or decreased as required, as long as it fits within the RAM available. The compiler places a minimum limit of 20 for stack size. If the stack overflows or underflows, the microcontroller will trigger an exception. The compiler’s command library routines make extensive use of the stack for saving and restoring WREG SFRs, therefore, make sure the stack is large enough to accommodate all the Gosub/Return commands, as well as temporary data used.

When 64-bit floating point Double variables are being used in trigonometry routines, it is important to increase the stack size because the library routines use the stack intensively as temporary storage. A stack size of 200 words will usually suffice. If the program resets intermittently, the stack size is too small and the microcontroller is executing an over/under stack exception.

Declare Stack_Expand = 1 or 0 or On or Off Whenever an interrupt handler is used within a BASIC program, it must context save and restore critical SFRs and variables that would otherwise get overwritten. It uses the microcontroller’s stack for temporary storage of the SFRs and variables, therefore the stack will increase with every interrupt handler used within the program. If this behaviour is undesirable, the above declare will disable it. However, the user must make sure that the stack is large enough to accommodate the storage, otherwise an exception will be triggered by the microcontroller.