[英]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。
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
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.我目前还没有遇到任何问题。
#
or /
.#
或/
。//
and /**/
to avoid preprocessor issues.//
和/**/
可能更安全,以避免预处理器问题。 However, if you keep in mind the hidden gotchas, you should be ok./
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. ##
更通用,但可能会导致代码更混乱。Try # or // or /* */.尝试 # 或 // 或 /* */。 Might work
可能有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.