Commenting syntax for x86 AT&T syntax assembly

前端 未结 3 655
别那么骄傲
别那么骄傲 2021-01-02 05:52

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

相关标签:
3条回答
  • 2021-01-02 06:18

    Avoid Using # Comments

    There are many hidden landmines with # as a comment. # is also the GCC preprocessor directive symbol. This means that this:

    # 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 #. Words you shouldn't use: include, if, else, line, define, and anything else in the C preprocessor. Oddly enough, these do seem to be case-sensitive, so capitalizing # Include actually works.

    If you insist on using #'s, ## Line comment will work. Just don't use it on any lines that are part of a #define macro because ## is also the token pasting operator.

    Use C-style Comments

    Now for what your TAs and profs should have told you.

    In most cases/architectures, // and / for line comments are supported:

    • // Rest of line comment Works pretty much as you'd expect from C. However, 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. (If you're worried about compatibility, GCC has apparently allowed this since April of 2000, so you're probably fine.)

    • / Start line comment may only be used at the start of a line (after whitespace removal).

    Of course, /* Use this for block comments */.

    In short, only use // and /**/ (C-style), and you'll most likely be ok. There are some examples of this here. Like Peter has commented, you don't have to preprocess, but it's a good idea to use something that works in all cases.

    Technical Differences

    There is a small difference in how these comments are treated. When compiled using gcc -S (create *.s code), the C /**/ and // comments are scraped out, but the # comments are left in.

    0 讨论(0)
  • 2021-01-02 06:25

    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.

    0 讨论(0)
  • 2021-01-02 06:44

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

    0 讨论(0)
提交回复
热议问题