[fpc-pascal] Inline ASM code

Sven Barth pascaldragon at googlemail.com
Thu Aug 24 11:14:34 CEST 2017


Am 24.08.2017 08:32 schrieb "LacaK" <lacak at zoznam.sk>:
>
> Hi *,
>
> I need store result of floating point calculation (in my example
arctan()) in memory pointed by some variable. See this code:
> var a: single; pa: PSingle;
>   asm
>       fild dy
>       fild dx
>       fpatan
>       fstp a
>       fwait
>   end;
>   pa^ := a;
>
> It works, but is there any way how to store result directly to "pa^" in
assembler ?
> I have tried:
>       ...
>       fpatan
>       fstp pa^ ... fstp (pa) ... but this does not compile ... I need
store to memory location pointed by pa "variable"
>       fwait
>   end;
>

You need to retrieve the value of pa into a register and then store at that
address. Something like this:

=== code begin ===
mov edx, pa
fstp [pa]
=== code end ===

Note 1: not tested
Note 2: you might want to check which register you can use for that
Note 3: I hope you keep the global and the assembler function in the same
unit, because inter-unit access to globals changes when dynamic packages
are enabled for a target

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170824/b1f387e4/attachment.html>


More information about the fpc-pascal mailing list