Quick start manual
Inline assembly code
13-9
Expressions
the built-in assembler cannot compute the value of X + Y at compile time. In this case,
to move the sum of X and Y into Z you would use
asm
MOV EAX,X
ADD EAX,Y
MOV Z,EAX
end;
In a Delphi expression, a variable reference denotes the contents of the variable. But in
an assembler expression, a variable reference denotes the address of the variable. In
Delphi the expression X + 4 (where X is a variable) means the contents of X plus 4,
while to the built-in assembler it means the contents of the word at the address four
bytes higher than the address of X. So, even though you’re allowed to write
asm
MOV EAX,X+4
end;
this code doesn’t load the value of X plus 4 into AX; instead, it loads the value of a
word stored four bytes beyond X. The correct way to add 4 to the contents of X is
asm
MOV EAX,X
ADD EAX,4
end;
Expression elements
The elements of an expression are constants, registers, and symbols.
Constants
The built-in assembler supports two types of constant: numeric constants and string
constants.
Numeric constants
Numeric constants must be integers, and their values must be between –2,147,483,648
and 4,294,967,295.
By default, numeric constants use decimal notation, but the built-in assembler also
supports binary, octal, and hexadecimal. Binary notation is selected by writing a B
after the number, octal notation by writing an O after the number, and hexadecimal
notation by writing an H after the number or a $ before the number.
Numeric constants must start with one of the digits 0 through 9 or the $ character.
When you write a hexadecimal constant using the H suffix, an extra zero is required
in front of the number if the first significant digit is one of the digits A through F. For
example, 0BAD4H and $BAD4 are hexadecimal constants, but BAD4H is an identifier
because it starts with a letter.