[next] [prev] [prev-tail] [tail] [up]

### 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 stored in well-known registers, and if there are more parameters than free registers, they are pushed from left to right 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 also passed to the procedure.
3. If the called procedure or function is an object method, then the pointer to self is passed to the procedure.
4. If the procedure or function is nested in another function or procedure, then the frame pointer of the parent procedure is passed to 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 | extra parameters | Yes
+12 | function result | Yes
+8 | self | Yes
+4 | Return address | No
+0 | Frame pointer of parent procedure | Yes

6.7.1 Parameter alignment

[next] [prev] [prev-tail] [front] [up]