2

I'm trying to compile an inline assembly code in clang (Windows). So,I have the following code:

int main(int, char **) {
  asm("mov %eax,$4;");
}

I tried compiling it using clang++ -masm=intel main.cpp but it complains about mnemonic operand size main.cpp:4:7: error: unknown use of instruction mnemonic without a size suffix, because it was still using AT&T syntax.
I have tried using

asm(".intel_syntax;"
      "mov %eax,$4;");

But it complains about using .intel_syntax main.cpp:3:7: error: unknown token in expression asm(".intel_syntax;")

0xDEADC0DE
  • 323
  • 3
  • 12
  • [Last I checked](https://stackoverflow.com/a/58154963/224132), it didn't seem possible to get clang to use Intel-syntax inline asm. – Peter Cordes Aug 08 '20 at 21:35
  • This would be a better example if it wasn't totally broken. e.g. `asm("mov $4, %eax" ::: "eax")` for the AT&T example. (source first, destination last, and a clobber to tell the compiler about the register you step on). And your intel-syntax attempt is still using AT&T decorations on register names and immediates. The GAS `.intel_syntax noprefix` version of that instruction is `mov eax, 4`. Clang's assembler would reject that even in a stand-alone `.s` file. – Peter Cordes Aug 08 '20 at 21:53
  • 1
    Adding `noprefix` seems to work but it brakes when using inputs/ouputs. for example `asm(".intel_syntax noprefix; mov eax,%0 \n\t" ::"i"(10): "eax");`, gives the error ` error: unknown token in expression mov eax,$10`, it seems the prefix is added to inputs/ouputs. – 0xDEADC0DE Aug 09 '20 at 06:41
  • Does this answer your question? [How to set gcc or clang to use Intel syntax permanently for inline asm() statements?](https://stackoverflow.com/questions/38953951/how-to-set-gcc-or-clang-to-use-intel-syntax-permanently-for-inline-asm-stateme) – Peter Cordes Aug 06 '22 at 22:18

0 Answers0