Go to the first, previous, next, last section, table of contents.

GPC inline assembler

GNU Pascal has an inline assembler, but it is quite different from Borland's one. I have not yet found reasonable documentation about the use of this assembler, but I found out the following:

The syntax is

  asm ( 'movl $12345678, %eax' );
  asm ( 'movl %eax, %edx' );

to move the (hex) value `$12345678' to the EAX register and then to the EDX register. The String argument of the asm "procedure" is passed as a string to the assembler stage of the compilation. The assembler follows the AT&T, not the Intel syntax. Note that the order of operands is reversed with respect to the order you know from Intel assemblers and that the size of the arguments is appended to the mnemonic as a suffix b (byte), w (word = 2 bytes), or l (long = 4 bytes).

You can learn about the GNU assembler syntax when compiling your program with `-S' (see above) and looking into the resulting assembler source.

To access Pascal symbols from the assembler, do something like

  asm ( 'movl %%eax, %0' : : 'rm' ( MyVariable ) );

Here, the % signs in front of the register names are doubled because % gets some special meaning. The 'rm' means that the operand may be in a register or in memory.

(If somebody knows more about the GNU assembler syntax, please, please, please explain it to me or point me to some reasonable documentation about it! <peter.gerwinski@uni-essen.de>)


Go to the first, previous, next, last section, table of contents.