Quick start manual

Program control
12-3
Parameters and function results
Register saving conventions
Procedures and functions must preserve the EBX, ESI, EDI, and EBP registers, but
can modify the EAX, EDX, and ECX registers. When implementing a constructor or
destructor in assembler, be sure to preserve the DL register. Procedures and
functions are invoked with the assumption that the CPU’s direction flag is cleared
(corresponding to a CLD instruction) and must return with the direction flag cleared.
Note
Delphi language procedures and functions are generally invoked with the
assumption that the FPU stack is empty: The compiler tries to use all eight FPU stack
entries when it generates code.
When working with the MMX and XMM instructions, be user to preserve the values
of the xmm and mm registers. Delphi functions are invoked with the assumption that
the x87 FPU data registers are available for use by x87 floating point instructions.
That is, the compiler assumes that the EMMS/FEMMS has been called after MMX
operations. Delphi functions do not make any assumptions about the state and
content of xmm registers. They do not guarantee that the content of xmm registers is
unchanged.
Function results
The following conventions are used for returning function result values.
Ordinal results are returned, when possible, in a CPU register. Bytes are returned
in AL, words are returned in AX, and double-words are returned in EAX.
Real results are returned in the floating-point coprocessor’s top-of-stack register
(ST(0)). For function results of type Currency, the value in ST(0) is scaled by 10000.
For example, the Currency value 1.234 is returned in ST(0) as 12340.
For a string, dynamic array, method pointer, of variant result, the effects are the
same as if the function result were declared as an additional var parameter
following the declared parameters. In other words, the caller passes an additional
32-bit pointer that points to a variable in which to return the function result.
Pointer, class, class-reference, and procedure-pointer results are returned in EAX.
For static-array, record, and set results, if the value occupies one byte it is returned
in AL; if the value occupies two bytes it is returned in AX; and if the value
occupies four bytes it is returned in EAX. Otherwise, the result is returned in an
additional var parameter that is passed to the function after the declared
parameters.