Quick start manual
13-2
Delphi Language Guide
Assembler statement syntax
Register use
In general, the rules of register use in an asm statement are the same as those of an
external procedure or function. An asm statement must preserve the EDI, ESI, ESP,
EBP, and EBX registers, but can freely modify the EAX, ECX, and EDX registers. On
entry to an asm statement, EBP points to the current stack frame and ESP points to
the top of the stack. Except for ESP and EBP, an asm statement can assume nothing
about register contents on entry to the statement.
Assembler statement syntax
This syntax of an assembly statement is
Label: Prefix Opcode Operand
1
, Operand
2
where Label is a label, Prefix is an assembly prefix opcode (operation code), Opcode is
an assembly instruction opcode or directive, and Operand is an assembly expression.
Label and Prefix are optional. Some opcodes take only one operand, and some take
none.
Comments are allowed between assembly statements, but not within them. For
example,
MOV AX,1 {Initial value} { OK }
MOV CX,100 {Count} { OK }
MOV {Initial value} AX,1; { Error! }
MOV CX, {Count} 100 { Error! }
Labels
Labels are used in built-in assembly statements as they are in the Delphi language—
by writing the label and a colon before a statement. There is no limit to a label’s
length. As in Delphi, labels must be declared in a label declaration part in the block
containing the asm statement. The one exception to this rule is local labels.
Local labels are labels that start with an at-sign (@). They consist of an at-sign
followed by one or more letters, digits, underscores, or at-signs. Use of local labels is
restricted to asm statements, and the scope of a local label extends from the asm
reserved word to the end of the asm statement that contains it. A local label doesn’t
have to be declared.