如何编写宏来重复特定地址之前的内容?

How do I write a macro to repeat something up to a specific address?

The .org directive 将位置计数器递增到指定的偏移量,并用指定的值填充额外的字节。

.org 123, 1 @ Pads 1s until we reach address 123.

我想写一个宏来做类似的事情,但更复杂 "fill." 比如:

@ 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, and the dot symbol 显然不是绝对的。

<instantiation>:2:5: error: expected absolute expression
.if . < 10
    ^

到目前为止我发现的唯一解决方法是更改​​宏的界面以获取重复计数,而不是结束地址。有没有更好的方法?

基于

.macro my_pad new_lc
.if . - base < \new_lc
    .4byte 0xdeadbeef
    my_pad \new_lc
.endif
.endm

.data
base:
my_pad 100

对于常量,宏也可以使用 .fill \new_lc-(.-base), 4, 0xdeadbeef 实现,无需递归。