简体   繁体   English

x86 AT&T 语法汇编的注释语法

[英]Commenting syntax for x86 AT&T syntax assembly

The Intel syntax has comments using the semicolon. Intel 语法有使用分号的注释。 When I switched to AT&T, it actually tried to interpret the comments.当我切换到 AT&T 时,它实际上试图解释这些评论。

What is the comment syntax for AT&T assembly? AT&T 汇编的注释语法是什么?

Comments for at&t assembler are:对 at&t 汇编程序的评论是:

 # 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. ///* */注释仅在.S文件中受支持,因为 GCC 在组装之前对它们运行 C 预处理器。 For .s files, the actual assembler itself ( as ) only handles # as a comment character, for x86.对于.s文件,实际的汇编器本身 ( as ) 仅将#作为注释字符处理,对于 x86。

For some other ISAs, GAS uses other comment characters, for example @ for ARM.对于其他一些 ISA,GAS 使用其他注释字符,例如@代表 ARM。

GNU AS Comments GNU AS 评论

The following are handled by as directly.以下由as直接处理。 (Not the C preprocessor.) (不是 C 预处理器。)

  • # Comments - Works as a "rest of line" comment. #注释 - 用作“行的其余部分”注释。

    Important Caveat: # is also the GCC preprocessor directive symbol.重要警告: #也是 GCC 预处理器指令符号。 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 # .在行的开头(空格不计算在内)会给你error: #include expects "FILENAME" or <FILENAME> with gcc,即使在#之后有一个空格。

    However, these are case-sensitive, so capitalizing # Include actually works:但是,这些是区分大小写的,因此大写# Include实际上有效:

     # 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.) (只是不要在属于#define宏的任何行上使用它,因为##也是标记粘贴操作符。)

  • / 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) C 风格的注释(预处理器)

These work if the C preprocessor is run on the source file.如果 C 预处理器在源文件上运行,这些工作。

In most architectures, the following are supported:在大多数体系结构中,支持以下内容:

  • // Rest of line comment works pretty much as you'd expect from C. // Rest of line comment与您对 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 */ . /* 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 / .如果你不允许预处理的一切,选择的GNU AS评论风格,一个#/
  • If you're sure you will preprocess everything, it may be safer to go with the C-style comments // and /**/ to avoid preprocessor issues.如果您确定预处理所有内容,则使用 C 样式注释///**/可能更安全,以避免预处理器问题。 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可能有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM