omron — Program Stacks

Program Stacks Program Stacks When subroutine calls are made, eV+ uses aeV+n internal storage area called a stack to save information required by the executing program. This information includes: l The name and step number of the calling program. l Data necessary to access subroutine arguments. l The values of any automatic variables specified in the called program. The eV+ system allows you to explicitly allocate storage to the stack for each program task. Thus, the amount of stack space can be tuned for a particular application to optimize the use of system memory. Stacks can be made arbitrarily large, limited only by the amount of memory available on your system.

Stack Requirements When a eV+ program is executed in a given task, each program stack is allocated 32 kilobytes of memory. This value can be adjusted, once the desired stack requirements are determined, by using the STACK monitor command (for example, in a start-up monitor command program). See the eV+ Operating System Reference Guide for information on monitor commands. One method of determining the stack requirements of a program task is simply to execute its program. If the program runs out of stack space, it stops with the error message:

*Too many subroutine calls* or *Not enough stack space* If this happens, use the STACK monitor command to increase the stack size and then issue the RETRY monitor command to continue program execution. In this case, you do not need to restart the program from the beginning. (The STATUS command will tell you how much stack space a failed task requested.) Alternatively, you can start by setting a large stack size before running your program. After the program has been run, and all the execution paths have been followed, use the STATUS monitor command to look at the stack statistics for the program task. The stack MAX value shows how much stack space your program task needs in order to execute.

The stack size can then be set to the maximum shown, with a little extra for safety. If it is impossible to invoke all the possible execution paths, the theoretical stack limits can be calculated from the figures provided in the following table. You can calculate the worst-case stack size by adding up the overhead for all the program calls that can be active at one time. Divide the total by 1024 to get the size in kilobytes. Use this number in the STACK monitor command to set the size. eV+Language User's Guide, v2.x, 18318-000 Rev A Page 25