Question

The Intel syntax has comments using the semicolon. When I switched to AT&T, it actually tried to interpret the comments.

What is the comment syntax for AT&T assembly?

Was it helpful?

Solution

Comments for at&t assembler are:

 # this is a comment
 /* this is a comment */

According to the fourth result Google gave me

// 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.

For some other ISAs, GAS uses other comment characters, for example @ for ARM.

OTHER TIPS

GNU AS Comments

The following are handled by as directly. (Not the C preprocessor.)

  • # Comments - Works as a "rest of line" comment.

    Important Caveat: # is also the GCC preprocessor directive symbol. The preprocessor runs first, so this means that if you are running it,

    # include comments in your code to get full credit
    

    at the beginning of the line (whitespaces don't count) will give you error: #include expects "FILENAME" or <FILENAME> with gcc, even with a space after the #.

    However, these are case-sensitive, so capitalizing # Include actually works:

    # Include comments in your code to get full credit
    

    While it is generally good practice to capitalize the first letter of your comments anyway, you can use ## as a just-in-case measure. (Just don't use it on any lines that are part of a #define macro because ## is also the token pasting operator.)

  • / comments - Start of line comment

    These may only be used at the start of a line (after whitespace removal).

    / This is OK
    xor %eax, %eax / This is *not* ok
    

C-style Comments (preprocessor)

These work if the C preprocessor is run on the source file.

In most architectures, the following are supported:

  • // Rest of line comment works pretty much as you'd expect from C.

    In rare cases this causes problems with . pseudo-ops. To work around this, I just use a block comment or just move the comment to the preceding line.

  • /* Use this for block comments */. I currently haven't run into any issues with this.

So what do I use?

  • If you're not allowed to preprocess everything, choose one of the GNU AS Comment styles, # or /.
  • If you're sure you will preprocess everything, it may be safer to go with the C-style comments // and /**/ to avoid preprocessor issues. However, if you keep in mind the hidden gotchas, you should be ok.
  • If you're concerned about having to handle both, choose either / or ## so you don't have to worry about the preprocessor or lack thereof on any one file. ## is more versatile, but may lead to messier code.
  • Whatever the case may be, choose one and be consistent.

Try # or // or /* */. Might work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top