Quick start manual
13-12
Delphi Language Guide
Expressions
The following symbols cannot be used in asm statements:
• Standard procedures and functions (for example, WriteLn and Chr).
• String, floating-point, and set constants (except when loading registers).
• Labels that aren’t declared in the current block.
•The @Result symbol outside of functions.
The following table summarizes the kinds of symbol that can be used in asm
statements.
With optimizations disabled, local variables (variables declared in procedures and
functions) are always allocated on the stack and accessed relative to EBP, and the
value of a local variable symbol is its signed offset from EBP. The assembler
automatically adds [EBP] in references to local variables. For example, given the
declaration
var Count: Integer;
within a function or procedure, the instruction
MOV EAX,Count
assembles into MOV EAX,[EBP–4].
The built-in assembler treats var parameters as a 32-bit pointers, and the size of a var
parameter is always 4. The syntax for accessing a var parameter is different from that
for accessing a value parameter. To access the contents of a var parameter, you must
first load the 32-bit pointer and then access the location it points to. For example,
function Sum(var X, Y: Integer): Integer; stdcall;
begin
asm
MOV EAX,X
MOV EAX,[EAX]
MOV EDX,Y
ADD EAX,[EDX]
MOV @Result,EAX
end;
end;
Table 13.4 Symbols recognized by the built-in assembler
Symbol Value Class Type
Label Address of label Memory reference Size of type
Constant Value of constant Immediate value 0
Type 0 Memory reference Size of type
Field Offset of field Memory Size of type
Variable Address of variable Memory reference Size of type
Procedure Address of procedure Memory reference Size of type
Function Address of function Memory reference Size of type
Unit 0 Immediate value 0
@Result Result variable offset Memory reference Size of type