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

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

The following symbols cannot be used in asm statements:

  • Standard procedures and functions (for example, WriteLn and Chr).
  • String, floating-point, and set constants (except when loading registers).
  • Labels that aren't declared in the current block.
  • The @Result symbol outside of functions.

The following table summarizes the kinds of symbol that can be used in asm statements. Symbols recognized by the built-in assembler

Symbol

Value

Class Type

Label

Address of label

Memory referenceSize of type

Constant

Value of constant

Immediate value 0

Type

0

Memory referenceSize of type

Field

Offset of field

Memory Size of type

Variable

Address of variable or address of a pointer to the variableMemory referenceSize of type

Procedure Address of procedure

Memory referenceSize of type

Function

Address of function

Memory referenceSize of type

Unit

0

Immediate value 0

@Result

Result variable offset

Memory referenceSize of type

With optimizations disabled, local variables (variables declared in procedures and functions) are always allocated on the stack and accessed relative to EBP, and the value of a local variable symbol is its signed offset from EBP. The assembler automatically adds [EBP] in references to local variables. For example, given the declaration var Count: Integer;

within a function or procedure, the instruction

MOV EAX,Count assembles into mov eax,[ebp4] .

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 EDX,Y

MOV @Result,EAX

Identifiers can be qualified within asm statements. For example, given the declarations type

TPoint = record

end;

TRect = record

the following constructions can be used in an asm statement to access fields.

MOV EAX,P.X

MOV EDX,P.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[EDX].B.X

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment