next up previous contents
Next: Linking issues Up: Using assembly language Previous: Calling mechanism

Telling the compiler what registers have changed

  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 (extended) registers you modify in your assembly code. They can be one of 'EAX', 'EBX', 'ECX', 'EDX', 'EDI', 'ESI' for the Intel processor.

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.



Michael Van Canneyt
Tue Mar 31 16:50:06 CEST 1998