The stack is used to pass parameters to procedures or functions, to store local variables, and, in some cases, to return function results.
When a function or procedure is called, then the following is done by the compiler :
The resulting stack frame upon entering looks as in table (8.1).
Offset | What is stored | Optional ? |
+x | parameters | Yes |
+12 | function result | Yes |
+8 | self | Yes |
+4 | Frame pointer of parent procedure | Yes |
+0 | Return address | No |
The stack is cleared with the ret I386 instruction, meaning that the size of all pushed parameters is limited to 64K.
Under the DOS targets , the default stack is set to 256Kb. This value cannot be modified for the GO32V1 target. But this can be modified with the GO32V2 target using a special DJGPP utility stubedit. It is to note that the stack size may be changed with some compiler switches, this stack size, if greater then the default stack size will be used instead, otherwise the default stack size is used.
Under Linux, stack size is only limited by the available memory by the system.
Under OS/2, stack size is determined by one of the runtime environment variables set for EMX. Therefore, the stack size is user defined.
All depending on the processor target, the stack can be cleared in two manners, if the target processor is a MC68020 or higher, the stack will be cleared with a simple rtd instruction, meaning that the size of all pushed parameters is limited to 32K.
Otherwise on MC68000/68010 processors, the stack clearing mechanism is sligthly more complicated, the exit code will look like this:
{ move.l (sp)+,a0 add.l paramsize,a0 move.l a0,-(sp) rts }
Under AmigaOS, stack size is determined by the user, which sets this value using the stack program. Typical sizes range from 4K to 40K.
Under Atari TOS, stack size is currently limited to 8K, and it cannot be modified. This may change in a future release of the compiler.