This is the mail archive of the
binutils@sourceware.org
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" <binutils at sourceware dot org>
- Cc: "R. Diez" <rdiezmail-binutils at yahoo dot de>
- Date: Mon, 30 Apr 2012 23:47:21 +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> <20120430115411.GA1925@ratatosk> <1335790394.40554.YahooMailNeo@web171302.mail.ir2.yahoo.com>
- Reply-to: dvalin at internode dot on dot net
Please keep this on-list.
On 30.04.12 13:53, R. Diez wrote:
> > The second "1:" demonstrates label re-use, and forward/backward
> > referencing.
>
> Thanks for your answer.
>
> What happens if MACRO_B defines itself a "1:" label? It will collide
> with that of calling MACRO_A, won't it?
You appear to have neither tried the given examples, nor read "info as".
Please do both, as advised. Then try the posted alternative to your
example, to easily answer that question.
> > 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.
>
> What happens if several nested macro invocations use \@ ? At which
> points will this variable be incremented then? I mean, say MACRO_A
> defines a label based on \@, then invokes MACRO_B and MACRO_C, then it
> tries to reference that \@ label, will the macro invocations count
> have changed in the meantime?
See "info as". It is also immediately clear once you expend the effort
of trying it out, even without prior reading. Learning by doing
surpasses all other methods. (Not least if unfamiliarity with English is
hampering comprehension of the documentation and advice already given.)
Try invoking:
unique_labels_x3 alpha ; Labels .LL0001 - 3, lbl_0 - 2, &
unique_labels_x3 beta ; ulx_alpha, ulx_beta, ulx_gamma
unique_labels_x3 gamma ; are generated.
Have a look not only at the labels generated, but also under the heading
"DEFINED SYMBOLS" in the .lst file your assembly generates. Then try
nesting macros.
Incidentally, there's a typo in the unique_labels_x3 demo macro.
It should be "jmp ulx_\dest", for full didactic benefit.
(And jumps to the other labels could be added, to show the assembler
using them all.)
Happy experimenting!
Erik
--
Documentation is like sex: when it is good, it is very, very good;
and when it is bad, it is better than nothing.
- Dick Brandon