宏在GAS中替换为常数 [英] Macro substituting a constant number in GAS
问题描述
X86 GNU Assembly上的那个宏怎么了?表示链接期间未定义符号S.
What't wrong with that macro on X86 GNU Assembly? It says the symbol S is undefined during linking.
.macro S size=40
\size
.endm
我正在使用它
mov %eax, S
推荐答案
宏用于为您经常使用的代码创建模板,而不是输入常数.因此,我不相信汇编程序会在表达式中进行宏扩展.由于只需要一个数字,因此可以使用.set
定义一个常量.
Macros are used to create templates for code you frequently use, not to input a constant number. As such, I do not believe the assembler does macro expansion within an expression. Since you simply want a number, you could use .set
to define a constant.
.set S, 40
mov %eax, S
此外,如果您通常使用intel语法,请确保您意识到这段代码在做什么:当前,它将eax的值存储在内存中的地址0x28处.如果要将数字40放在eax中,则需要反转操作数,并在S前面使用美元符号.
Also, in case you usually use intel syntax, make sure you realize what this code is doing: It currently stores the value of eax in memory at the address 0x28. If you want to put the number 40 in eax, you need to reverse the operands and use a dollar sign in front of S.
mov $S, %eax
这篇关于宏在GAS中替换为常数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!