【发布时间】:2020-03-20 05:03:01
【问题描述】:
The .org directive 将位置计数器前进到指定的偏移量,并用指定的值填充额外的字节。
.org 123, 1 @ Pads 1s until we reach address 123.
我想编写一个宏来做类似的事情,但使用更复杂的“填充”。喜欢:
@ Pads some_special_symbol until we reach address new_lc.
.macro my_pad new_lc
.if . < \new_lc
.4byte some_special_symbol
my_pad \new_lc
.endif
.endm
GAS 抱怨这种实现是因为 the .if directive requires an absolute expression 和 the dot symbol 显然不是绝对的。
<instantiation>:2:5: error: expected absolute expression
.if . < 10
^
到目前为止,我发现的唯一解决方法是更改宏的接口以进行重复计数,而不是结束地址。有没有更好的办法?
【问题讨论】:
-
.fill can take a 4 byte constant too 但也许这和
.if有同样的问题。编辑:是的。 -
取
.和某个符号之间的距离。 -
@fuz 你有完整的例子吗?
-
@Maxpm 现在懒得写了。基本上,如果两个符号在同一节中,则它们的差异是一个常数,可以用于此目的。将一个符号放在该部分的开头,另一个符号为
.。请注意,这仅允许您找到与此文件中部分开头的差异,这可能不是链接后的整体开头。
标签: assembly macros gnu-assembler