[fpc-pascal]Var parameter passing to asm procedure

Florian Klaempfl fpk at gmx.org
Thu Aug 5 16:56:28 CEST 2004


Ivan Stamenkovic wrote:

> Hi,
> 
> I have a problem when trying to pass some variable parameters to a
> procedure writen using integrated assembler. I have reduced the
> problem to the following code:
> 
> program IncrementDemo;
> {$R+}
> {$asmmode intel}
> 
> var
>    a: dword;
> 
> procedure increment(var x: dword); assembler;
>    asm
>       push ds { Is DS saved by default? }
> 
>       lds ebx, x
>       mov eax, [ebx]     { Line with the problem }
>       inc eax
>       mov [ebx], eax
> 
>       pop ds
>    end;
> 
> begin
>    write('Enter a number: ');
>    readln(a);
>    increment(a);
>    writeln('Result is: ', a, '.')
> end.
> 
> Line with the problem is marked above. If I tried using
> mov eax, [bx]
> integrated environment would report that 16-bit references are not
> supported. With EBX instead of BX program reports run-time error 216.
> 
> I have tried using both DOS and Win32 targets. FPC 1.0.10, Win32.
> 
> Another Q: Is it necessary to save the segment registers' contents
> when entering an assembler procedure?

FPC is 32 bit (flat memory modell) compiler so don't mess with segment 
registers!

So:
  procedure increment(var x: dword); assembler;
     asm
       mov ebx, x
       mov eax, [ebx]     { Line with the problem }
       inc eax
       mov [ebx], eax
     end;




More information about the fpc-pascal mailing list