Compiler-explorer: Intel syntax for Pascal

Created on 22 Jul 2018  路  4Comments  路  Source: compiler-explorer/compiler-explorer

The "Intel syntax" button is greyed out in Pascal, so I tried searching for the compiler option to switch to Intel syntax.

I found from Google a page saying that you have to use the option -Amasm. I tried that and got this error

Warning: Assembler output selected "MASM" is not compatible with "Linux for x86-64"
Warning: "AS" assembler use forced
Target OS: Linux for x86-64

That's obvious since you don't run masm in Linux, but I suppose you can run masm in wine in case other solutions don't work

I found some other sources that said you must add the option -eval-command="set disassembly-flavor intel" but it didn't work either

Then I checked the Free Pascal compiler options and found that it supports the following output formats

  -A<x>  Output format:
      -Adefault  Use default assembler
      -Aas       Assemble using GNU AS
      -Agas      Assemble using GNU GAS
      -Agas-darwin Assemble darwin Mach-O64 using GNU GAS
      -Amasm     Win64 object file using ml64 (Microsoft)
      -Apecoff   PE-COFF (Win64) using internal writer
      -Aelf      ELF (Linux-64bit) using internal writer
      -Ayasm     Assemble using Yasm (experimental)
      -Anasm     Assemble  using Nasm (experimental)
      -Anasmwin64 Assemble Win64 object file using Nasm (experimental)
      -Anasmelf  Assemble Linux-64bit object file using Nasm (experimental)
      -Anasmdarwin Assemble darwin macho64 object file using Nasm (experimental)

https://www.freepascal.org/docs-html/3.0.0/user/userap1.html

We can tell as and gas to output Intel syntax with -masm=intel, but I tried using -ao "-masm=intel", -ao"-masm=intel", -ao"masm=intel" with only errors returned

If I used -Agas I got this error

Warning: Assembler output selected "GAS" is not compatible with "Linux for x86-64"
Warning: "AS" assembler use force

Other Linux assemblers like -Anasm or -Ayasm don't work

So do you have any solutions for this? In summary I've got the below ideas

  • Install nasm or yasm and use that
  • Find the way to pass the option -masm=intel to as somehow with -ao
  • Run masm in wine
enhancement lang-pascal question request

All 4 comments

In the regular mode without any options, we instruct FPC to leave the intermediate assembly file for viewing. You can instruct use the -A options for that, but not more than that. We're dependent on what the compiler can generate.

-Anasm should work (and we can make compiler explorer detect it), but on a system where Nasm is installed correctly, the same error message occurs. So there seems to be a bug when generating nasm style assembly, but I'm not sure what that might be. It might just be because it's still experimental.

In the fpc 304 compiler's sourcecode, I can see the error is generated when trying to write 64bit aligned consts, but I'm not sure why this error is raised. I will see if I can leave a bugreport on their bugtracker.

The one sure way to get Intel style assembly, is if you use the disassembler on the generated binaries. Which the [IOIOIO] button can do in Compiler Explorer.

No bugreport needed, it seems the code in question is fixed in the current trunk of FPC, so with the next version I'm sure this problem will be fixed and we'll be able to offer Nasm assembly output.

Woa, it took 2 years, but I see that v3.2.0 is finally out

FPC 3.2.0 is now live on the website. We have not enabled intel notation by default yet, because the output needs some filtering and line highlighting.
But you can already try it out by passing -Anasmelf in 3.2.0 (doesn't work in earlier versions because of a bug in fpc as mentioned earlier)

Example: https://godbolt.org/z/rKGT55

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daniel-j-h picture daniel-j-h  路  4Comments

yesudeep picture yesudeep  路  4Comments

mattgodbolt picture mattgodbolt  路  4Comments

Slabity picture Slabity  路  3Comments

pps83 picture pps83  路  5Comments