Quick start manual
Inline assembly code
13-5
Assembler statement syntax
When an identifier precedes a DB, DW, or DD directive, it causes the declaration of a
byte-, word-, or double-word-sized variable at the location of the directive. For
example, the assembler allows the following:
ByteVar DB ?
WordVar DW ?
IntVar DD ?
ƒ
MOV AL,ByteVar
MOV BX,WordVar
MOV ECX,IntVar
The built-in assembler doesn’t support such variable declarations. The only kind of
symbol that can be defined in an inline assembly statement is a label. All variables
must be declared using Delphi syntax; the preceding construction can be replaced by
var
ByteVar: Byte;
WordVar: Word;
IntVar: Integer;
ƒ
asm
MOV AL,ByteVar
MOV BX,WordVar
MOV ECX,IntVar
end;
SMALL and LARGE can be used determine the width of a displacement:
MOV EAX, [LARGE $1234]
This instruction generates a “normal” move with a 32-bit displacement ($00001234).
MOV EAX, [SMALL $1234]
The second instruction will generate a move with an address size override prefix and
a 16-bit displacement ($1234).
SMALL can be used to save space. The following example generates an address size
override and a 2-byte address (in total three bytes)
MOV EAX, [SMALL 123]
as opposed to
MOV EAX, [123]
which will generate no address size override and a 4-byte address (in total four
bytes).
Two additional directives allow assembly code to access dynamic and virtual
methods: VMTOFFSET and DMTINDEX.
VMTOFFSET retrieves the offset in bytes of the virtual method pointer table entry of
the virtual method argument from the beginning of the virtual method table (VMT).
This directive needs a fully specified class name with a method name as a parameter
(for example, TExample.VirtualMethod), or an interface name and an interface
method name.