Quick start manual
13-14
Delphi Language Guide
Expressions
Immediate values and memory references cause different code to be generated when
used as operands. For example,
const
Start = 10;
var
Count: Integer;
ƒ
asm
MOV EAX,Start { MOV EAX,xxxx }
MOV EBX,Count { MOV EBX,[xxxx] }
MOV ECX,[Start] { MOV ECX,[xxxx] }
MOV EDX,OFFSET Count { MOV EDX,xxxx }
end;
Because Start is an immediate value, the first MOV is assembled into a move
immediate instruction. The second MOV, however, is translated into a move memory
instruction, as Count is a memory reference. In the third MOV, the brackets convert
Start into a memory reference (in this case, the word at offset 10 in the data segment).
In the fourth MOV, the OFFSET operator converts Count into an immediate value
(the offset of Count in the data segment).
The brackets and OFFSET operator complement each other. The following asm
statement produces identical machine code to the first two lines of the previous asm
statement.
asm
MOV EAX,OFFSET [Start]
MOV EBX,[OFFSET Count]
end;
Memory references and immediate values are further classified as either relocatable or
absolute. Relocation is the process by which the linker assigns absolute addresses to
symbols. A relocatable expression denotes a value that requires relocation at link
time, while an absolute expression denotes a value that requires no such relocation.
Typically, expressions that refer to labels, variables, procedures, or functions are
relocatable, since the final address of these symbols is unknown at compile time.
Expressions that operate solely on constants are absolute.
The built-in assembler allows you to carry out any operation on an absolute value,
but it restricts operations on relocatable values to addition and subtraction of
constants.