Sign in Join

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

Mailing lists / fpc-pascal / 2012-08

Inline bytes

12 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Rainer Stratmann

How is it possible to put some inline bytes in the code like the former inline( $1f , $ef , $1A );
instruction?

Jonas Maebe
to Rainer Stratmann

Rainer Stratmann wrote on Thu, 09 Aug 2012:

How is it possible to put some inline bytes in the code like the former inline( $1f , $ef , $1A ); instruction?
{$asmmode att}
asm
   .byte $0x1f, $0xef, $0x1a
end;
{$asmmode intel}
asm
   db $1a, $ef, $1a
end;

If this is supposed to be the only code/data inside an assembler routine, make sure to also add "assembler; nostackframe;" to that routine's modifiers to prevent the compiler from setting up a stack frame and/or insert stack alignment code.

Jonas

Rainer Stratmann
to Jonas Maebe: Rainer Stratmann wrote on Thu, 09 Aug 2012: {$asmmode att} asm .byte $0x1f, $0xef, $0x1a…
Jonas Maebe wrote 14 lines
Rainer Stratmann wrote on Thu, 09 Aug 2012: > How is it possible to put some inline bytes in the code like the former > inline( $1f , $ef , $1A ); > instruction? {$asmmode att} asm .byte $0x1f, $0xef, $0x1a end; {$asmmode intel} asm db $1a, $ef, $1a end;

Thanks, the next problem then is: I wanted to do that in an inline procedure but if the compiler detects an asm statement then inline is disabled(!).

Henry Vermaak
to Rainer Stratmann
Rainer Stratmann wrote 18 lines
Am Thursday 09 August 2012 15:14:29 schrieb Jonas Maebe: > Rainer Stratmann wrote on Thu, 09 Aug 2012: >> How is it possible to put some inline bytes in the code like the former >> inline( $1f , $ef , $1A ); >> instruction? > > {$asmmode att} > asm > .byte $0x1f, $0xef, $0x1a > end; > > {$asmmode intel} > asm > db $1a, $ef, $1a > end; Thanks, the next problem then is: I wanted to do that in an inline procedure but if the compiler detects an asm statement then inline is disabled(!).

Maybe a macro?

Henry

Jonas Maebe
to Rainer Stratmann: Thanks, the next problem then is: I wanted to do that in an inline procedure but if the…

Rainer Stratmann wrote on Thu, 09 Aug 2012:

Show quoted text 5 lines
Am Thursday 09 August 2012 15:14:29 schrieb Jonas Maebe: > {$asmmode att} > asm > .byte $0x1f, $0xef, $0x1a > end;

I made an error here, the "$" should be removed (see Thomas' mail)

Show quoted text 7 lines
> {$asmmode intel} > asm > db $1a, $ef, $1a > end; Thanks, the next problem then is: I wanted to do that in an inline procedure but if the compiler detects an asm statement then inline is disabled(!).

That's correct, it is not possible inline assembler statements in FPC. You can try a macro instead:

{$macro on}
{$define IReallyKnowWhatIAmDoing:=asm .byte 0x1f, 0xef, 0x1a end}
begin
   IReallyKnowWhatIAmDoing;
end.

You will have to declare the macro in a common include file or in every main source file if you want to use it in more than one compilation module though.

Jonas

Rainer Stratmann
to Jonas Maebe
Jonas Maebe wrote 12 lines
> Thanks, the next problem then is: I wanted to do that in an inline > procedure but if the compiler detects an asm statement then inline is > disabled(!). That's correct, it is not possible inline assembler statements in FPC. You can try a macro instead: {$macro on} {$define IReallyKnowWhatIAmDoing:=asm .byte 0x1f, 0xef, 0x1a end} begin IReallyKnowWhatIAmDoing;

Sounds good!

end.

Same thing: inlining disabled(!).

Show quoted text 8 lines
You will have to declare the macro in a common include file or in every main source file if you want to use it in more than one compilation module though. Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Jonas Maebe
to Rainer Stratmann

Rainer Stratmann wrote on Thu, 09 Aug 2012:

Show quoted text 17 lines
Am Thursday 09 August 2012 15:33:52 schrieb Jonas Maebe: > > Thanks, the next problem then is: I wanted to do that in an inline > > procedure but if the compiler detects an asm statement then inline is > > disabled(!). > > That's correct, it is not possible inline assembler statements in FPC. > You can try a macro instead: > > {$macro on} > {$define IReallyKnowWhatIAmDoing:=asm .byte 0x1f, 0xef, 0x1a end} > > begin > IReallyKnowWhatIAmDoing; Sounds good! > end. Same thing: inlining disabled(!).

The idea is to use the macro instead of a function call, not to use the macro inside a function that you then try to inline. A macro is just text substitution, it will never have a different effect than typing its contents directly at the place where the macro is used.

Jonas

Rainer Stratmann
to Jonas Maebe
Jonas Maebe wrote
The idea is to use the macro instead of a function call, not to use the macro inside a function that you then try to inline. A macro is just text substitution, it will never have a different effect than typing its contents directly at the place where the macro is used.

To avoid disabling procedure/function inlining when the compiler finds an asm instruction it would be good to have at least the mentioned former

inline( $AB, $CD , $EF , ... );

back.

Is that possible?

Macros have to defined for each unit again so this is not userfriendly if a programmer changes a macro.

Jonas Maebe
to Rainer Stratmann

Rainer Stratmann wrote on Thu, 09 Aug 2012:

Show quoted text 8 lines
To avoid disabling procedure/function inlining when the compiler finds an asm instruction it would be good to have at least the mentioned former inline( $AB, $CD , $EF , ... ); back. Is that possible?

There are no plans to do so, and even if it were added it would be quite possible that this would also disable inlining the containing routine for implementation reasons.

Macros have to defined for each unit again so this is not userfriendly if a programmer changes a macro.

A macro can be defined in a file that is included in all units, so then you only have to change it in one place.

Jonas

Rainer Stratmann
to Jonas Maebe
Jonas Maebe wrote
if it were added it would be quite possible that this would also disable inlining the containing routine for implementation reasons.

I think the reason for disabling is that in the asm code can be identifyers and jumplabels which are difficult to handle then.

In the inline( $AB , $CD , ... ) instruction is only pure data, so for me there is no reason to disable the inlining then.

Jonas Maebe
to Rainer Stratmann

Rainer Stratmann wrote on Thu, 09 Aug 2012:

Show quoted text 10 lines
Am Thursday 09 August 2012 17:09:57 schrieb Jonas Maebe: > if it were added it would be > quite possible that this would also disable inlining the containing > routine for implementation reasons. I think the reason for disabling is that in the asm code can be identifyers and jumplabels which are difficult to handle then. In the inline( $AB , $CD , ... ) instruction is only pure data, so for me there is no reason to disable the inlining then.

inline() can contain identifiers and labels just like assembler blocks. But again: there are no plans to add support for inline().

Jonas