What's the best way to define local labels in an assembler macro?
Mon Apr 30 13:48:00 GMT 2012
On 30.04.12 11:08, R. Diez wrote:
> What's the best way to define local labels in an assembler macro?
There are several ways. However, the quickest in your case:
> Â .macro MACRO_A
> Â Â Â local_label_1: Â Â Â local_label_2:
> Â Â Â MACRO_B local_label_2Â Â // Passes one of the local labels down.
> Â Â Â jump local_label_1
> Â .endm
1: // A "jump 1f" in MACRO_B allows exit.
The second "1:" demonstrates label re-use, and forward/backward
Try invoking MACRO_A several times, and observe what happens in the
> Can pseudo-variable \@ help?
Since \@ merely adds numbers, taken from the count of macro invocations,
to the label name, it's just another way of making the label unique.
And '.altmacro and its "LOCAL xxx" syntax' works just as well, simply
generating unique labels looking like ".LL0001".
Trying your example with either would work. If there is any doubt, you
could try a demo macro which I used to teach myself this stuff, long
.macro unique_labels_x3 dest
LOCAL lbl ; Unique label is generated by the assembler.
; (It will start with "L", so is omitted from
; the symbol table. Can be put into symbol
lbl: ; table, using .global )
lbl_\@: ; Label generation from macro count.
ulx_\dest: ; Label generation from an argument.
(The 1f, 4b, type of local labels seemed too simple to include.)
It is necessary to read "info as" a few times, then experiment, to gain
a good feel for the behaviour, which is really fairly simple.
"You know, it's at times like this when I'm trapped in a Vogon airlock
with a man from Betelgeuse and about to die of asphyxiation in deep
space that I really wish I'd listened to what my mother told me when I
"Why, what did she tell you?"
"I don't know, I didn't listen!"
- Douglas Adams, "Hitchhiker's Guide to the Galaxy"
More information about the Binutils