How is it possible to put some inline bytes in the code like the former inline( $1f , $ef , $1A );
instruction?
Mailing lists / fpc-pascal / 2012-08
Inline bytes
12 messages · 4 people ·
- JJonas Maebe 5
- RRainer Stratmann 5
- HHenry Vermaak 1
- TThomas Schatzl 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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
How is it possible to put some inline bytes in the code like the former inline( $1f , $ef…
Hi,
Rainer Stratmann wroteHow is it possible to put some inline bytes in the code like the former inline( $1f , $ef , $1A ); instruction?
Not sure if it is the official way, but the following works:
with {$asmmode att}
asm
.byte 0x1f, 0xef, 0x1a
end;
and with {$asmmode intel}
asm
db $1f, $ef, $1a
end;
Hth,
Thomas
Rainer Stratmann wrote on Thu, 09 Aug 2012: {$asmmode att} asm .byte $0x1f, $0xef, $0x1a…
Jonas Maebe wrote 14 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(!).
Rainer Stratmann wrote 18 lines
Maybe a macro?
Henry
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
I made an error here, the "$" should be removed (see Thomas' mail)
Show quoted text 7 lines
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
Jonas Maebe wrote 12 lines
Sounds good!
end.
Same thing: inlining disabled(!).
Show quoted text 8 lines
Rainer Stratmann wrote on Thu, 09 Aug 2012:
Show quoted text 17 lines
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
Jonas Maebe wroteThe 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.
Rainer Stratmann wrote on Thu, 09 Aug 2012:
Show quoted text 8 lines
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
Jonas Maebe wroteif 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.
Rainer Stratmann wrote on Thu, 09 Aug 2012:
Show quoted text 10 lines
inline() can contain identifiers and labels just like assembler blocks. But again: there are no plans to add support for inline().
Jonas
