6.7 Parameter passing

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 (6.5).



Table 6.5: Stack frame when calling a procedure (32-bit model)



Offset What is stored Optional?



+x parameters Yes
+12 function result Yes
+8 self Yes
+4 Return address No
+0 Frame pointer of parent procedure Yes





   Parameter alignment