Subsections


3 Using Assembly language

Free Pascal supports inserting assembler statements in your code. The mechanism for this is the same as under Turbo Pascal. There are, however some substantial differences, as will be explained in the following sections.

1 Intel 80x86 Inline assembler


1 Intel syntax

Free Pascal supports Intel syntax for the Intel family of Ix86 processors in it's asm blocks.

The Intel syntax in your asm block is converted to AT&T syntax by the compiler, after which it is inserted in the compiled source. The supported assembler constructs are a subset of the normal assembly syntax. In what follows we specify what constructs are not supported in Free Pascal, but which exist in Turbo Pascal:

The Intel inline assembler supports the following macros:

@Result
represents the function result return value.
Self
represents the object method pointer in methods.


2 AT&T Syntax

Free Pascal uses the GNU as assembler to generate its object files for the Intel Ix86 processors. Since the GNU assembler uses AT&T assembly syntax, the code you write should use the same syntax. The differences between AT&T and Intel syntax as used in Turbo Pascal are summarized in the following:

More information about the AT&T syntax can be found in the as manual, although the following differences with normal AT&T assembly must be taken into account:

The AT&T inline assembler supports the following macros:

__RESULT
represents the function result return value.
__SELF
represents the object method pointer in methods.
__OLDEBP
represents the old base pointer in recusrive routines.

2 Motorola 680x0 Inline assembler

The inline assembler reader for the Motorola 680x0 family of processors, uses the Motorola Assembler syntax (q.v). A few differences do exit:

The inline assembler supports the following macros:

@Result
represents the function result return value.
Self
represents the object method pointer in methods.


3 Signaling changed registers

When the compiler uses variables, it sometimes stores them, or the result of some calculations, in the processor registers. If you insert assembler code in your program that modifies the processor registers, then this may interfere with the compiler's idea about the registers. To avoid this problem, Free Pascal allows you to tell the compiler which registers have changed. The compiler will then avoid using these registers. Telling the compiler which registers have changed is done by specifying a set of register names behind an assembly block, as follows:
asm
  ...
end ['R1', ... ,'Rn'];
Here R1 to Rn are the names of the registers you modify in your assembly code.

As an example:

   asm
   movl BP,%eax
   movl 4(%eax),%eax
   movl %eax,__RESULT
   end ['EAX'];
This example tells the compiler that the EAX register was modified.



Free Pascal Compiler
2001-09-22