简体   繁体   English

在 AArch64 的 GNU 汇编器中打破长宏参数列表

[英]Breaking long macro argument list in GNU assembler for AArch64

I'm writing assembly code targeting ARMv8 (AArch64) in GNU assembler.我正在用 GNU 汇编器编写针对 ARMv8 (AArch64) 的汇编代码。 Not sure if it matters, but I'm coding directly in my ARMv8 target (a Raspberry Pi board) running Linux.不确定这是否重要,但我直接在运行 Linux 的 ARMv8 目标(Raspberry Pi 板)中进行编码。

I have a macro with a very long argument list (as in, over 60 arguments) -- I know, this is just wrong, please don't shoot me.我有一个带有长参数列表的宏(例如,超过 60 个参数)——我知道,这是错误的,请不要开枪。

For readability, I'd like to break this argument list over multiple lines, ie something like this:为了便于阅读,我想将此参数列表分成多行,例如:

.macro my_macro arg1, arg2, arg3, arg4,
                arg5, arg6, arg7, arg8,
                // ...
                arg61, arg62, arg63, arg64

    // macro code goes here

.endm

I'd also like to do the same when instantiating the macro.我也想在实例化宏时做同样的事情。

Unfortunately, as soon as I try to insert a line break in the macro declaration, I get the following error:不幸的是,一旦我尝试在宏声明中插入换行符,就会收到以下错误:

test.s: Assembler messages:
test.s:123: Error: Bad parameter list for macro `my_macro'

As for inserting a line break in the macro instantiation, although I don't directly receive an error, the code doesn't assemble because all parameters after the line break are ignored, ie as though I had instantiated the macro with fewer parameters than it expects, so the missing ones default to an empty string.至于在宏实例化中插入换行符,虽然我没有直接收到错误,但代码没有汇编,因为换行符之后的所有参数都被忽略了,即好像我用比它更少的参数实例化了宏期望,因此缺少的默认为空字符串。

According to the manual :根据手册

The ';'这 ';' character can be used instead of a newline to separate statements.可以使用字符而不是换行符来分隔语句。

I tried to add a ;我试图添加一个; to the end of each line, ie:到每一行的末尾,即:

.macro my_macro arg1, arg2, arg3, arg4, ;
                arg5, arg6, arg7, arg8, ;
                // ...
                arg61, arg62, arg63, arg64

    // macro code goes here

.endm

This made no difference.这没什么区别。 Same thing for a line break in the macro instantiation.宏实例化中的换行符也是如此。 I also tried other characters, such as # , @ and // with no luck.我还尝试了其他字符,例如#@//没有运气。

So: is it possible to insert line breaks in the middle of the argument list in a macro declaration or instantiation?那么:是否可以在宏声明或实例化的参数列表中间插入换行符?

I don't know a way to do this in the assembler itself.我不知道在汇编程序本身中执行此操作的方法。 However, a common practice when writing Unix-style assembly is to run your source through the C preprocessor before passing it on to the assembler.然而,编写 Unix 风格的汇编程序时的一个常见做法是在将源代码传递给汇编程序之前通过 C 预处理器运行您的源代码。 It's common enough that the gcc command will do it for you if you give your source file a name ending in .S with an upper case S.如果您为源文件指定一个以.S结尾且带有大写 S 的名称,那么gcc命令将为您执行此操作很常见。

The C preprocessor does support backslash line continuation, so in that case you can write C 预处理器确实支持反斜杠继续,所以在这种情况下你可以写

.macro my_macro arg1, arg2, arg3, arg4,     \
                arg5, arg6, arg7, arg8,     \
                // ...
                arg61, arg62, arg63, arg64  

    // macro code goes here
.endm

and the whole .macro directive will be seen as a single line by the assembler.整个.macro指令将被汇编器视为一行。

Having the C preprocessor also gives you the ability to use C-style macros with #define , in case that is useful.拥有 C 预处理器还使您能够使用带有#define的 C 风格宏,以防万一有用。

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

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