Methods | Documentation

boolean byte code data dptr file function high idata lcall memory module procedure record register segment type value xdata 8051
Assembler Compiler internals Methods

# Methods

Methods are always reentrant. Before a call to the method is made the following is pushed on the XDATA stack:

> 1. Address for String result (for functions which return String)
> 2. All parameters in order in which they were declared

On call to static method the following parameters must be in registers:

> 1. R3R2: Self address

On call to virtual method the following parameters must be in registers:

> 1. DPTR: Self address (will be placed in R3R2 by system routine for virtual method call)
> 2. R2 (or R3R2): Offset of VMT address
> 3. R0 (or R1R0): Offset of method address
> 4. R5R4: VMT parameter

On call to dynamic method the following parameters must be in registers:

> 1. DPTR: Self address (will be placed in R3R2 by system routine for dynamic method call)
> 2. R2 (R3R2): Offset of DMT address
> 3. R1: Dynamic method index
> 4. R5R4: VMT parameter

On call to constructor method the following parameters must be in registers:

> 1. R3R2: Self address (If nil, constructor call is via New)
> 2. R5R4: VMT parameter (address of VMT - normal call, $0000 means static call -no initialization of VMT address in Self)
> 3. Returns Self (address of allocated object) in R3R2

On call to destructor method the following parameters must be in registers:

> 1. R3R2: Self address
> 2. R4: VMT parameter ($00: normal destructor call, $01: call via Dispose)

Called method on entry:

> 1. pushes XBP
> 2. sets XBP to point to the top of pushed parameters
> 3. pushes Self parameter which was passed in R3R2
> 4. pushes VMT parameter which was passed in R5R4
> 5. reserves space for local variables (increases XSP accordingly)

On exit called method pops saved XBP and removes all pushed parameters from XDATA stack. XDATA stack during reentrant procedure call looks like this:

XDATA STACK low memory |
Pushed address for String result (for functions which return String) |
Pushed parameters |
Outer procedure's XBP (if there is outer procedure) | XBP - 4
Saved XBP | XBP - 2
Self address | XBP
VMT parameter | XBP + 2
Result variable (for functions which return simple type | XBP + 4
Local variables and temporary storage |
XDATA STACK high memory | XSP