0

When trying to compile the following program stub:

;put 1 into accumulator register
mov     $1,     %eax

I get an error on:

$ gcc d.s

d.s: Assembler messages: d.s:1: Error: no such instruction: `put 1 into accumulator register'

Why doesn't the assembler skip over the comment, or is there something I'm doing wrong here to insert in a comment?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
David542
  • 104,438
  • 178
  • 489
  • 842
  • You have to use `#` or `//` or `/*...*/`, as `;' is a comment in Intel syntax, while GCC uses AT&T syntax – JCWasmx86 Aug 01 '20 at 19:17
  • @JCWasmx86 thanks, that fixed it. Want to put it into an answer and I'll go ahead and accept it? – David542 Aug 01 '20 at 19:18
  • No, I don't think such a comment is worth an answer, as it is neither good nor even reaches the guidelines for answers – JCWasmx86 Aug 01 '20 at 19:19
  • @JCWasmx86: `//` and `/* */` comments won't work in a `.s` file, only in a `.S` where GCC will run the C preprocessor on it before assembling. – Peter Cordes Aug 01 '20 at 20:19
  • @PeterCordes I just tried with both `.s` and `.S`. Working with both – Waqar Aug 01 '20 at 20:29
  • 1
    @Waqar: Are you putting the comment at the start of the line? `/` works as a line-comment character in GAS, but something like `mov $1 + 2, %edi // do the math at assemble time` won't assemble with GAS. Even that will assemble with `clang`, though; are you on a Mac where `as` is actually clang / llvm-as in disguise, and `gcc -static foo.s` is actually `clang`? On my GNU/Linux desktop, `clang -static foo.s` will assemble a file with `//` not at the start of a line. – Peter Cordes Aug 01 '20 at 20:39
  • Ah yes, you are right. The `//` or `/*` style comments don't work if they are on the same line as assembly code. But they work on separate lines. And no, I am on Linux with `gnu-as` – Waqar Aug 01 '20 at 20:43

0 Answers0