Recent

Author Topic: how to detect which ASM mode the compiler is in?  (Read 1723 times)

jamie

  • Hero Member
  • *****
  • Posts: 6030
how to detect which ASM mode the compiler is in?
« on: November 18, 2023, 12:48:46 am »
I ran into a strange issue where I decided to do an online assembler...

ASm <<<< Unsupported assembler parser.
 ...
END:

 Compiler stopped at the ASM, stating there was an unsupported assembler parser.?

 Setting the compiler in the project to Default, Intel or ATT made no difference, however, setting it in source prior to the attempted assembler did.

{$ASMMODE ATT}
...all is fine
///


How can I determine the current ASM mode at the point where the compiler chokes?

 I did this in a patch of code in an existing project instead of starting a new one.

Also this is FPC 3.0.4 but I am not sure if that really makes a difference here.
The only true wisdom is knowing you know nothing

ASerge

  • Hero Member
  • *****
  • Posts: 2196
Re: how to detect which ASM mode the compiler is in?
« Reply #1 on: November 18, 2023, 09:02:36 am »
I ran into a strange issue where I decided to do an online assembler...

ASm <<<< Unsupported assembler parser.
 ...
END:

 Compiler stopped at the ASM, stating there was an unsupported assembler parser.?
As far as I know the asm operator is enabled in all modes.

Avinash

  • Full Member
  • ***
  • Posts: 117
Re: how to detect which ASM mode the compiler is in?
« Reply #2 on: November 18, 2023, 10:01:53 am »
not working...
Code: Pascal  [Select][+][-]
  1. begin
  2.   {$ASMMODE INTEL}
  3.   asm
  4.     mov ebx,eax
  5.   end;
  6.  
  7.   {$PUSH}
  8.   {$ASMMODE ATT}
  9.   asm
  10.     movl %eax,%ebx
  11.   end;
  12.   {$POP}
  13.  
  14.   asm
  15.     mov ebx,eax
  16.   end;
  17. end.

jamie

  • Hero Member
  • *****
  • Posts: 6030
Re: how to detect which ASM mode the compiler is in?
« Reply #3 on: November 18, 2023, 04:47:28 pm »
The only other thing I left out is that this is done with the 32-bit compiler.

it's strange this happens, I have not found the reason for it, yet.
The only true wisdom is knowing you know nothing

ASerge

  • Hero Member
  • *****
  • Posts: 2196
Re: how to detect which ASM mode the compiler is in?
« Reply #4 on: November 18, 2023, 07:16:07 pm »
not working...
As documented in $ASMMODE : Assembler mode (Intel 80x86 only)
These switches are local, and retain their value to the end of the unit that is compiled, unless they are replaced by another directive of the same type

Avinash

  • Full Member
  • ***
  • Posts: 117
Re: how to detect which ASM mode the compiler is in?
« Reply #5 on: November 18, 2023, 07:47:11 pm »
These switches are local, and retain their value to the end of the unit that is compiled, unless they are replaced by another directive of the same type

The same is said for local directives in general:

The local directives influence the compiler’s behavior from the moment they’re encountered until the moment another switch annihilates their behavior, or the end of the current unit or program is reached.

And at the same time:

1.2.63 $PUSH : Save compiler settings
The $PUSH directive saves the current values of all local compiler directives

1.2.62 $POP : Restore compiler settings
The $POP directive restores the values of all local compiler directives with the last values that were stored


And, among other things, it would be convenient in a case like Jamie's.
« Last Edit: November 18, 2023, 07:49:49 pm by Avinash »

ASerge

  • Hero Member
  • *****
  • Posts: 2196
Re: how to detect which ASM mode the compiler is in?
« Reply #6 on: November 18, 2023, 08:30:41 pm »
And, among other things, it would be convenient in a case like Jamie's.
For everything but that. None of the local directives say about the actions as for $ASMMODE. Perhaps in $PUSH and $POP it was also possible to specify that with the exception of $ASMMODE.

Avinash

  • Full Member
  • ***
  • Posts: 117
Re: how to detect which ASM mode the compiler is in?
« Reply #7 on: November 18, 2023, 08:57:12 pm »
For everything but that. None of the local directives say about the actions as for $ASMMODE. Perhaps in $PUSH and $POP it was also possible to specify that with the exception of $ASMMODE.

...and with the exception of $CALLING? The list is not complete...

Code: Pascal  [Select][+][-]
  1. function WrFirst: Integer;
  2. begin
  3.   Write('FIRST ');
  4. end;
  5.  
  6. function WrSecond: Integer;
  7. begin
  8.   Write('SECOND ');
  9. end;
  10.  
  11. {$CALLING PASCAL}
  12. procedure TestPascal1(X,Y: Integer);
  13. begin
  14. end;
  15.  
  16. {$PUSH}
  17. {$CALLING STDCALL}
  18. {$POP}
  19.  
  20. procedure TestPascal2(X,Y: Integer);
  21. begin
  22. end;
  23.  
  24. begin
  25.   TestPascal1(WrFirst, WrSecond);
  26.   WriteLn;
  27.   TestPascal2(WrFirst, WrSecond);
  28. end.

Output:
Quote
FIRST SECOND
SECOND FIRST

jamie

  • Hero Member
  • *****
  • Posts: 6030
Re: how to detect which ASM mode the compiler is in?
« Reply #8 on: November 18, 2023, 09:16:59 pm »
Not sure where my problem is, I still use older lazarus because it uses 3.0.4 which compiles a DLL I have correctly, anything newer I have problems with the DLL.

  But in anycase, the problem of the same versions in the 64 bit IDE and compiler does not have this issue which I use most of the time.

 Getting back to the 32 bit one.

 if i use {$Mode DElphi} then it works. but using ObjFpc it does not work.

 However, If I put into custom options the -RAtt for example or just -RDefault. it works. But that is only doable per project.

 In the parser menu it makes no difference what I select, it has no parser for ASM while in objFpc mode unless I do an inline switch or use the custom options per project.

 Strange I've never seen this before, maybe because it works correctly in the 64 bit target.


As for the trunk, I always test with the 64 bit install so I don't know if there is some issue there.

This is on windows.


In case you would like to see the message
Quote
Compile Project, Target: C:\Users\xxxxxx\AppData\Local\Temp\project1.exe: Exit code 1, Errors: 1
unit1.pas(34,3) Fatal: Selected assembler reader not supported


 
« Last Edit: November 18, 2023, 09:24:23 pm by jamie »
The only true wisdom is knowing you know nothing

Avinash

  • Full Member
  • ***
  • Posts: 117
Re: how to detect which ASM mode the compiler is in?
« Reply #9 on: November 18, 2023, 09:41:26 pm »
Full recompilation -B doesn't help?

jamie

  • Hero Member
  • *****
  • Posts: 6030
Re: how to detect which ASM mode the compiler is in?
« Reply #10 on: November 18, 2023, 10:06:12 pm »
No, I've already done that,

I looked around and it seems to be a known issue dating back to 2013 or so, exactly what I have found and it only seems to effect the 32 bit target version.


 That's fine, I'll live with it. Just never noticed it before.
The only true wisdom is knowing you know nothing

ASerge

  • Hero Member
  • *****
  • Posts: 2196
Re: how to detect which ASM mode the compiler is in?
« Reply #11 on: November 19, 2023, 08:15:02 am »
...and with the exception of $CALLING? The list is not complete...
Output:
Quote
FIRST SECOND
SECOND FIRST
An unfortunate example. The order in which functions are called does not correlate with the order in which parameters are passed. And generally undefined.
On my Win64, the program outputs
Quote
SECOND FIRST
SECOND FIRST

Avinash

  • Full Member
  • ***
  • Posts: 117
Re: how to detect which ASM mode the compiler is in?
« Reply #12 on: November 19, 2023, 09:40:20 am »
The order in which functions are called does not correlate with the order in which parameters are passed. And generally undefined.
If only this could be demonstrated by just one example...

Win64

https://wiki.freepascal.org/Win64/AMD64_API#Calling_convention
Calling conventions in Win64 for AMD
There is only one calling convention. Actually Microsoft include files are shared among Windows 32 bit and 64 bit. Functions modifiers like stdcall, cdecl and fastcall are ignored on 64bit windows since they use an unique calling convention.


Code: Pascal  [Select][+][-]
  1. procedure TestPascal1(X,Y: Integer); pascal;
  2. begin
  3.   WriteLn;
  4.   WriteLn('TestPascal1:');
  5.   WriteLn('Ofs(X) = ',Ofs(X));
  6.   WriteLn('Ofs(Y) = ',Ofs(Y));
  7. end;
  8.  
  9. procedure TestStd(X,Y: Integer); stdcall;
  10. begin
  11.   WriteLn;
  12.   WriteLn('TestStd:');
  13.   WriteLn('Ofs(X) = ',Ofs(X));
  14.   WriteLn('Ofs(Y) = ',Ofs(Y));
  15. end;
  16.  
  17. {$CALLING PASCAL}
  18. {$PUSH}
  19. {$CALLING STDCALL}
  20. {$POP}
  21.  
  22. procedure TestPascal2(X,Y: Integer);
  23. begin
  24.   WriteLn;
  25.   WriteLn('TestPascal2:');
  26.   WriteLn('Ofs(X) = ',Ofs(X));
  27.   WriteLn('Ofs(Y) = ',Ofs(Y));
  28. end;
  29.  
  30. begin
  31.   TestPascal1(0,0);
  32.   TestStd(0,0);
  33.   TestPascal2(0,0);
  34. end.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5424
  • Compiler Developer
Re: how to detect which ASM mode the compiler is in?
« Reply #13 on: November 19, 2023, 06:02:22 pm »
And at the same time:

1.2.63 $PUSH : Save compiler settings
The $PUSH directive saves the current values of all local compiler directives

1.2.62 $POP : Restore compiler settings
The $POP directive restores the values of all local compiler directives with the last values that were stored


That's a bug in the documentation, $Push and $Pop only work on all local switches, not directives. Plus some local directives like $Warn or $Align that all have been explicitely enabled for $Push/$Pop.


 

TinyPortal © 2005-2018