Subsections

12. Using assembler

Free Pascal supports the use of assembler in your code, but not inline assembler macros. To have more information on the processor specific assembler syntax and its limitations, see the Programmers' guide.

12.1 Assembler statements

The following is an example of assembler inclusion in your code.
 ...
 Statements;
 ...
 Asm
   your asm code here
   ...
 end;
 ...
 Statements;
The assembler instructions between the Asm and end keywords will be inserted in the assembler generated by the compiler. You can still use conditionals in your assembler, the compiler will recognise it, and treat it as any other conditionals.

Remark: Before version 0.99.1, Free Pascal did not support reference to variables by their names in the assembler parts of your code.

12.2 Assembler procedures and functions

Assembler procedures and functions are declared using the Assembler directive. The Assembler keyword is supported as of version 0.9.7. This permits the code generator to make a number of code generation optimizations.

The code generator does not generate any stack frame (entry and exit code for the routine) if it contains no local variables and no parameters. In the case of functions, ordinal values must be returned in the accumulator. In the case of floating point values, these depend on the target processor and emulation options.

Remark: From version 0.99.1 to 0.99.5 (excluding FPC 0.99.5a), the Assembler directive did not have the same effect as in Turbo Pascal, so beware! The stack frame would be omitted if there were no local variables, in this case if the assembly routine had any parameters, they would be referenced directly via the stack pointer. This was NOT like Turbo Pascal where the stack frame is only omitted if there are no parameters and no local variables. As stated earlier, starting from version 0.99.5a, Free Pascal now has the same behaviour as Turbo Pascal.



root
2000-12-20