简体   繁体   中英

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

The .org directive advances the location counter to a specified offset, and fills the extra bytes with a specified value.

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

I want to write a macro to do something similar, but with a more complex "fill." Like:

@ 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 complains about this implementation because the .if directive requires an absolute expression , and the dot symbol is apparently not absolute.

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

The only workaround I've found so far is to change the interface of the macro to take a repeat count, instead of an end address. Is there a better way?

Based on the comment of @fuz

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

.data
base:
my_pad 100

For a constant the macro can also be implemented using .fill \\new_lc-(.-base), 4, 0xdeadbeef without recursion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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