Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2023-04

FPC ARM inline Assembler

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vern

Does the current FPC compiler support  ARM inline assembler ?

If so what is the equivalent ARM command for {$ASMMODE intel}

Thanks
Brian

Sven Barth
to Vern

Vern via fpc-pascal schrieb am Do., 6.
Apr. 2023, 17:32:

Does the current FPC compiler support ARM inline assembler ?

Yes.

If so what is the equivalent ARM command for {$ASMMODE intel}

There is none, because only one syntax is supported.

Regards,
Sven

Jeppe Johansen
to Sven Barth
Sven Barth wrote 5 lines
If so what is the equivalent ARM command for {$ASMMODE intel} There is none, because only one syntax is supported.

Not entirely true. Two ARM assembly syntaxes are supported: "divided" (pre-UAL) and unified (UAL).

Maybe not all aspects of either syntax are supported. Especially NEON/Advanced SIMD stuff might not be supported.

Best Regards,
Jeppe

Vern
to Sven Barth: Vern via fpc-pascal schrieb am Do., 6. Apr. 2023, 17:32: Yes. There is none, because…

After reading the FPC manual more closely , the correct compiler command is {$ASMMODE default} where/default /is the native system ... in this case Orange Pi arm64 and the compiler now allows accepting ARM assembler instructions.

However it won't allow referencing a Pascal variable.

Here is an example (32-bit) of x86 inline assembler that works correctly

procedure MSBitTest ( DataIn : longword);
var
  MSBit : longword;
begin
  asm
   bsr eax , DataIn
   mov MsBit , eax
  end;
end;

.......... the ARM version fails (similar code : ignore the fact it is the reverse of BSR) ... what am I missing ?

procedure MSBitTest ( DataIn : longword);
var
  MSBit : longword;
begin
  asm
   clz w4 , DataIn
   mov MsBit , w4
  end;
end;

Regards
Vern

Sven Barth wrote 21 lines
Vern via fpc-pascal schrieb am Do., 6. Apr. 2023, 17:32: Does the current FPC compiler support  ARM inline assembler ? Yes. If so what is the equivalent ARM command for {$ASMMODE intel} There is none, because only one syntax is supported. Regards, Sven _______________________________________________ fpc-pascal maillist https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Jonas Maebe
to Vern
Vern wrote 13 lines
.......... the ARM version fails (similar code : ignore the fact it is the reverse of BSR) ... what am I missing ? procedure MSBitTest ( DataIn : longword); var  MSBit : longword; begin  asm   clz w4 , DataIn   mov MsBit , w4  end; end;

ARM is a load/store architecture, which means it only supports operations on values loaded in registers. Local variables are always allocated on the stack in procedures/functions with inline assembler blocks, so you need to use the "str" instruction to store w4 into MsBit. "mov" only works for register-register transfers on ARM.

Jonas

Vern
to Jonas Maebe

Works now!

Many Thanks
Vern

Jonas Maebe wrote 26 lines
On 06/04/2023 19:06, Vern via fpc-pascal wrote: > .......... the ARM version fails (similar code : ignore the fact it > is the reverse of BSR) ... what am I missing ? > > procedure MSBitTest ( DataIn : longword); > var >   MSBit : longword; > > begin >   asm >    clz w4 , DataIn >    mov MsBit , w4 >   end; > end; ARM is a load/store architecture, which means it only supports operations on values loaded in registers. Local variables are always allocated on the stack in procedures/functions with inline assembler blocks, so you need to use the "str" instruction to store w4 into MsBit. "mov" only works for register-register transfers on ARM. Jonas _______________________________________________ fpc-pascal maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Sven Barth
to Vern: After reading the FPC manual more closely , the correct compiler command is {$ASMMODE…

Vern via fpc-pascal schrieb am Do., 6.
Apr. 2023, 19:06:

Show quoted text 5 lines
After reading the FPC manual more closely , the correct compiler command is {$ASMMODE default} where* default *is the native system ... in this case Orange Pi arm64 and the compiler now allows accepting ARM assembler instructions

You don't need to use the $ASMMODE directive on non-x86 platforms, because the default syntax will always be selected. Also it's always possible to add assembly code.

Regards,
Sven