STACK - Pascal stack format.

(Single Segment Pascal only)

Description:

This file describes the format of the save area of the Pascal stack. A general discussion of the Pascal stack usage and calling sequence is given in "expl pascal call".

The table below gives the offset from the stack pointer "sp" and the interpretation of the value for each word of the save area.

Offset  Content
------  -------
-2      Address transferred to on function return,
        pointer to next trap block
-1      Address of nargs word in caller,
        pointer to function entry
0       Previous stack pointer
1       First word of first argument
n       First word of display
m       First local variable

Normally the address transferred to on return is the same as the address of the nargs word in the caller. However under special circumstances, return is not made directly to the caller but to some other code that does some form of function wrapup processing. Such a routine is referred to as a "trap".

Items separated by commas are stored in the upper and lower halves (resp.) of that word.

The two linkage words (-2 and -1) are used by the callee. A routine saves its return address within the stack frame of its caller before advancing the stack to its own stack frame.

Register Usage:

Index registers X0, X2, X3, X4, and address registers AR0, AR1, AR2, AR3 are available for use at any time as work registers and need not be restored. They are not perserved across a call, and so it is the caller's responsibility to save needed values before a call.

Index register X1 is used to hold the return address in a function call, and register X7 is used to pass a display pointer. Once the return address has been saved and the display copied, these registers may be used freely.

Index register X5 is saved across calls. It is available for use, but must be saved first and restored to its original value before the function returns.

Address register AR7 is used as the stack pointer (sp) and points to the current stack frame. Its value must not be changed within an executing function. It is only manipulated by the function entry/exit routines.

Index register X6 is used as the co-routine pointer (cp) for the currently active co-routine. Address registers AR4 and AR5 are used by the I/O package as the current read/write pointers (rd,wr). Address register AR6 is reserved for future use. None of these registers should be used by a user routine.

Copyright © 1996, Thinkage Ltd.