This is the mail archive of the
mailing list for the binutils project.
Re: What's the best way to define local labels in an assembler macro?
- From: Erik Christiansen <dvalin at internode dot on dot net>
- To: binutils at sourceware dot org
- Cc: "R. Diez" <rdiezmail-binutils at yahoo dot de>
- Date: Mon, 30 Apr 2012 21:54:11 +1000
- Subject: Re: What's the best way to define local labels in an assembler macro?
- References: <1335780492.6491.YahooMailNeo@web171306.mail.ir2.yahoo.com>
- Reply-to: dvalin at internode dot on dot net
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"