next up previous contents
Next: The heap Up: Memory issues Previous: The 32-bit model.

The stack

  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 :

  1. If there are any parameters to be passed to the procedure, they are pushed from right to left on the stack.
  2. If a function is called that returns a variable of type String, Set, Record, Object or Array, then an address to store the function result in, is pushed on the stack.
  3. If the called procedure or function is an object method, then the pointer to self is pushed on the stack.
  4. If the procedure or function is nested in another function or procedure, then the frame pointer of the parent procedure is pushed on the stack.
  5. The return address is pushed on the stack (This is done automatically by the instruction which calls the subroutine).

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
Table 8.1: Stack frame when calling a procedure

Intel x86 version

The stack is cleared with the ret I386 instruction, meaning that the size of all pushed parameters is limited to 64K.

DOS

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.

Linux

Under Linux, stack size is only limited by the available memory by the system.

OS/2

Under OS/2, stack size is determined by one of the runtime environment variables set for EMX. Therefore, the stack size is user defined.

Motorola 680x0 version

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
}

Amiga

Under AmigaOS, stack size is determined by the user, which sets this value using the stack program. Typical sizes range from 4K to 40K.

Atari

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.


next up previous contents
Next: The heap Up: Memory issues Previous: The 32-bit model.

Michael Van Canneyt
Thu Sep 10 14:04:11 CEST 1998