This is indeed a stupid idiosyncrasy of mine, but I can't stand the way GNU AS uses to insert a comment. I am too accustomed to the Sun way (the same used in most UNIX assemblers), that uses a simple slash "/" to comment out the code till the end of the line.
Do you know of a way to accomplish my little whim?
In assembly, comments are usually denoted by a semicolon ; , although GAS uses # for single line comments and /* … */ for block comments possibly spanning multiple lines.
// and /* */ comments are only supported in . S files because GCC runs the C preprocessor on them before assembling. For . s files, the actual assembler itself ( as ) only handles # as a comment character, for x86.
You need the comments when debugging, for example, to check that you have a correct algorithm and to check that the assembly language code implements it correctly.
Yes, keep using #
and you'll get used to it.
There may be ways of getting /
to work but then your code isn't just processor-specific but literally computer-specific. You're better-off getting used to small things than completely destroying the portability of your code to fancy a whim.
GNU GAS docs
Under the "Machine Dependencies" section, go into each arch, and then into "Syntax" and "Chars".
This documents what the comments are for each arch.
x86
https://sourceware.org/binutils/docs-2.26/as/i386_002dChars.html#i386_002dChars
The presence of a '#' appearing anywhere on a line indicates the start of a comment that extends to the end of that line.
If a '#' appears as the first character of a line then the whole line is treated as a comment, but in this case the line can also be a logical line number directive (see Comments) or a preprocessor control command (see Preprocessing).
If the --divide command line option has not been specified then the '/' character appearing anywhere on a line also introduces a line comment.
However, I either I'm missing something, or there is a bug, since my tests don't match the documentation.
OK:
/ mycomment
# mycomment
nop # mycomment
Fail:
nop / mycomment
This suggests that /
only works if it is the first character.
And --divide
didn't make any difference.
arm
https://sourceware.org/binutils/docs-2.26/as/ARM_002dInstruction_002dSet.html#ARM_002dInstruction_002dSet
The presence of a '@' anywhere on a line indicates the start of a comment that extends to the end of that line.
If a '#' appears as the first character of a line then the whole line is treated as a comment, but in this case the line could also be a logical line number directive (see Comments) or a preprocessor control command (see Preprocessing).
My tests with arm-linux-gnuabihf-as
confirm what the documentation says.
OK:
# mycomment
@ mycomment
nop @ mycomment
Fail:
nop # mycomment
aarch64
https://sourceware.org/binutils/docs-2.26/as/AArch64_002dChars.html#AArch64_002dChars
The presence of a '//' on a line indicates the start of a comment that extends to the end of the current line. If a `#' appears as the first character of a line, the whole line is treated as a comment.
Furthermore, this is also encouraged by the ARMv8-fb manual has at C1.2 "Structure of the A64 assembler language" itself:
In Example C1-1 on page C1-185, the sequence // is used as a comment leader and A64 assemblers are encouraged to accept this syntax.
My tests with aarch64-linux-gnuabihf-as
confirm what the documentation says.
OK:
// mycomment
# mycomment
nop // mycomment
Fail:
nop # mycomment
Personal recommendation
If you can choose, just always compile your assembly with gcc
or use the C preprocessor cpp
explicitly, and use C preprocessor comments:
/* mycomment */
because:
#
is bad as it could conflict with the #
preprocessor directivesTested on Ubuntu 16.04, Binutils 2.26.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With