Commenting syntax for x86 AT&T syntax assembly

爷,独闯天下 提交于 2020-08-18 14:13:54

问题


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?


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/17442444/commenting-syntax-for-x86-att-syntax-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!