[fpc-pascal] Interface with NASM

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Thu Sep 16 09:01:18 CEST 2010


Strange, I took a look and no idea why it doesn't work with the linked
.o file =) Maybe disassembling what nasm produces could show
something, but I don't know which GNU tool could be used for that...

The following program works for me:

program driver;

uses asmio;

{$ASMMODE att}

procedure tes2; pascal;
begin
  printc(Char(65));
end;

procedure tes; assembler; [alias:'tes'];
asm
  movl	$65,%eax
  push	%eax
  call printc
end;

begin
  tes2;
  tes;
end.

And here is the assembler generated:

fpc -s driver.pas
edit driver.s

.text
	.align 4
.globl	_P$DRIVER_TES2
_P$DRIVER_TES2:
	pushl	%ebp
	movl	%esp,%ebp
	subl	$24,%esp
	movl	%ebx,-12(%ebp)
	movl	%esi,-8(%ebp)
	movl	%edi,-4(%ebp)
	movl	$65,%eax
	movl	%eax,(%esp)
	call	L_ASMIO_PRINTC$CHAR$stub
	movl	-12(%ebp),%ebx
	movl	-8(%ebp),%esi
	movl	-4(%ebp),%edi
	leave
	ret

.text
	.align 4
.globl	_P$DRIVER_TES
_P$DRIVER_TES:
.reference tes
.globl	tes
tes:
.reference _P$DRIVER_TES
	subl	$12,%esp
	movl	$65,%eax
	pushl	%eax
	call	_ASMIO_PRINTC$CHAR
	addl	$12,%esp
	ret


-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list