Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commenting syntax for x86 AT&T syntax assembly

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?

like image 407
ihsoy ih Avatar asked Jul 03 '13 07:07

ihsoy ih


People also ask

How do you comment on an assembly arm?

armasm syntaxThe first semicolon on a line marks the beginning of a comment except where the semicolon appears inside a string literal. The end of the line is the end of the comment. A comment alone is a valid line.

How do I comment in Sasm?

The comment consists of the slash character (/) (ASCII 0x2F) followed by the text of the comment.

How do you comment on Intel?

You access this command by right-clicking inside an open file in the Quartus II Text Editor, and then clicking Comment Selection.

How do I comment on Nasm?

CommentsEditA single semi-colon is used for comments, and functions the same as double slash in C++: the compiler ignores from the semicolon to the next newline.


2 Answers

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.
like image 129
General Grievance Avatar answered Sep 27 '22 21:09

General Grievance


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.

like image 27
Zec Avatar answered Sep 27 '22 22:09

Zec