The built-in assembler treats var parameters as a 32-bit pointers, and the size of a var parameter is always 4. The
syntax for accessing a var parameter is different from that for accessing a value parameter. To access the contents
of a var parameter, you must first load the 32-bit pointer and then access the location it points to. For example,
function Sum(var X, Y: Integer): Integer; stdcall;
begin
asm
MOV EAX,X
MOV EAX,[EAX]
MOV EDX,Y
ADD EAX,[EDX]
MOV @Result,EAX
end;
end;
Identifiers can be qualified within asm statements. For example, given the declarations
type
TPoint = record
X, Y: Integer;
end;
TRect = record
A, B: TPoint;
end;
var
P: TPoint;
R: TRect;
the following constructions can be used in an asm statement to access fields.
MOV EAX,P.X
MOV EDX,P.Y
MOV ECX,R.A.X
MOV EBX,R.B.Y
A type identifier can be used to construct variables on the fly. Each of the following instructions generates the same
machine code, which loads the contents of [EDX] into EAX.
MOV EAX,(TRect PTR [EDX]).B.X
MOV EAX,TRect([EDX]).B.X
MOV EAX,TRect[EDX].B.X
MOV EAX,[EDX].TRect.B.X
Dostları ilə paylaş: