Quick start manual

Inline assembly code
13-11
Expressions
Registers
The following reserved symbols denote CPU registers in the inline assembler:
When an operand consists solely of a register name, it is called a register operand. All
registers can be used as register operands, and some registers can be used in other
contexts.
The base registers (BX and BP) and the index registers (SI and DI) can be written
within square brackets to indicate indexing. Valid base/index register combinations
are [BX], [BP], [SI], [DI], [BX+SI], [BX+DI], [BP+SI], and [BP+DI]. You can also index
with all the 32-bit registers—for example, [EAX+ECX], [ESP], and [ESP+EAX+5].
The segment registers (ES, CS, SS, DS, FS, and GS) are supported, but segments are
normally not useful in 32-bit applications.
The symbol ST denotes the topmost register on the 8087 floating-point register stack.
Each of the eight floating-point registers can be referred to using ST(X), where X is a
constant between 0 and 7 indicating the distance from the top of the register stack.
Symbols
The built-in assembler allows you to access almost all Delphi identifiers in assembly
language expressions, including constants, types, variables, procedures, and
functions. In addition, the built-in assembler implements the special symbol @Result,
which corresponds to the Result variable within the body of a function. For example,
the function
function Sum(X, Y: Integer): Integer;
begin
Result := X + Y;
end;
could be written in assembly language as
function Sum(X, Y: Integer): Integer; stdcall;
begin
asm
MOV EAX,X
ADD EAX,Y
MOV @Result,EAX
end;
end;
Table 13.3 CPU registers
32-bit general purpose EAX EBX ECX EDX 32-bit pointer or index ESP EBP ESI EDI
16-bit general purpose AX BX CX DX 16-bit pointer or index SP BP SI DI
8-bit low registers AL BL CL DL 16-bit segment registers CS DS SS ES
32-bit segment registers FS GS
8-bit high registers AH BH CH DH Coprocessor register stack ST