如何创建一个扩展为“(x+y*240)*2”这样的表达式的 GNU GAS 宏?
我正在使用 GAS 为 ARM Linux 构建一个程序,但我想做一些宏以使我的开发更加智能。然后我想知道:
我怎样才能为此做一个宏:(x+y*240)*2
,是x
和y
是 int
,将像这样使用:
mov r0, MACRO_SHOULD_BE_CALLED_HERE
我怎样才能做一个应该像这样调用的宏:
JUST_MACRO_CALLED_HERE_TO_DO_SOMETHING
它只会做一些已经在其中定义的事情,例如打印函数。
另外,如果我需要宏或函数调用的一些参数。我怎样才能做到呢?
PS:r0
是一个ARM寄存器,就像x86的eax
I'm building a program for ARM Linux using GAS, but I want to do some macros to make my development some more smart. Then I want to know:
How could I do a macro for this: (x+y*240)*2
, were x
and y
are int
, that will be used like this:
mov r0, MACRO_SHOULD_BE_CALLED_HERE
And how could I do a macro that should be called like this:
JUST_MACRO_CALLED_HERE_TO_DO_SOMETHING
That will just do something that is already defined inside it, like a print function for example.
Also, if I need some arguments on the macro or a function call. How I could do it?
PS: r0
is an ARM register, like eax
of x86
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GAS 与NASM 比较 - 宏 显示了执行参数化宏的方法,但它是简单的替换。
GAS vs NASM comparison - Macros shows ways of doing parametrized macros, but it's simple substitutions.
这是第一种类型的内联 gcc 示例。
或者在汇编程序中,
人们通常使用“C”预处理器。
Here is an inline gcc sample of the first type.
Or in assembler,
Often people use a 'C' pre-processor instead.
我从未见过像您第一个示例那样支持宏的汇编器。第二个例子非常简单——即使是最基本的汇编器文档也应该涵盖它。对于 GNU
as
,您可能想要这样的东西:用您想要的任何指令代替
...
。请小心汇编器宏,不要破坏用于保存重要数据的一堆寄存器。通常函数调用是解决这些问题的更好方法。
I've never seen an assembler that supported macros like you want for your first example. The second example is pretty straightforward though - even the most basic assembler documentation should cover it. For GNU
as
, you probably want something like:Put whatever instructions you want in place of the
...
.Be careful with assembler macros that you don't stomp on a bunch of registers that you were using to hold important data. Usually a function call is a better way to solve these problems.