|
| Previous: 4.2 Calling Conventions | TOC | Index | Back | Next: 4.4 Tcode Instruction Format |
A method should always begin with an MHDR instruction, which saves the caller's stack frame and instance context, creates a new stack frame, and shifts the instance context. It should end with an ENDM instruction, which restores the saved stack frame and instance context, and jumps back to the caller. Passing a message m with three numeric arguments to a global object O
O.m(1,2,3);
would be coded as follows:
NUM 1 NUM 2 NUM 3 LDGV LO CALL Lm CLEAN 4
The LDGV LO instruction pushes the address of the receiving object on the stack. The MHDR instruction loads this value into the SELF register, thereby shifting the instance context to the receiving object.
Each called method may expect the following stack configuration:
| FP+M | Argument #1 |
| FP+4 | Argument #N-1 |
| FP+3 | Argument #N |
| FP+2 | Receiver's Address |
| FP+1 | Return Address (saved by CALL or CALR) |
| FP+0 | Old SP (saved by MHDR) |
| FP-1 | Sender's Address (Old Instance Context, saved by MHDR) |
| FP-2 | Local Variable #1 |
| FP-3 | Local Variable #2 |
| FP-J | Local Variable #K |
| SP | ( Free memory below ) |
| Previous: 4.2 Calling Conventions | TOC | Index | Back | Next: 4.4 Tcode Instruction Format |