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
- Date: Tue, 1 May 2012 21:20:18 +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> <20120430134721.GB1925@ratatosk> <1335815353.8252.YahooMailNeo@web171301.mail.ir2.yahoo.com>
- Reply-to: dvalin at internode dot on dot net
On 30.04.12 20:49, R. Diez wrote:
> By the way, I did take the time to do some more tests, and your first
> recommendation already proved wrong.
No, the example you have posted (quoted below) is NOT the example
suggested, which was in reality:
1: // A "jump 1f" in MACRO_B allows exit.
Please _try_ it. (Optionally with any "2:" to "9:" label in MACRO_B, if
fiddling with examples absolutely must be done before they have been
tried at all.)
If you find your own construction:
> .macro MACRO_B
> Â 1:ÂÂÂ l.nop 2
> ÂÂÂÂÂÂÂ l.j 1b
> .macro MACRO_A
> Â 1:Â l.nop 1
> ÂÂÂÂÂ MACRO_B
> ÂÂÂÂÂ l.j 1b
to be "wrong", then feel free to stop doing it. Here the problem is
still failure to read "info as", which is enormously more informative
than the inadequate manpage. Perhaps the easiest way to grab a copy is:
$ sudo apt-get install binutils-doc
Since grubbing about in tree-structured documentation is a pain, just
hit "/label_". That search takes you directly to an enlightening
example, under the heading of "Local Labels".
Armed with understanding from the "info" documentation, we see that 1b
refers to the nearest "1:" backwards. To reach past that, to a more
distant local label, change "1:" and "1b" in MACRO_B to "2:" and "2b".
(Or conversely, make the more distant local label "2:" or "9:".)
And, as explained in the additional help in my code comment above, the
example can be extended to also demonstrate the 1b/1f working:
But as soon as you get around to reading the available documentation,
the penny drops, and it's all dead simple, innit? ;-)
Using just this one form of local labels, it is quite practical to make
up a small suite of macros which implement IF-ENDIF constructs in
assembler, with the jumps auto-adjusting when an ELSE is interposed.
It is only necessary to refrain from using the same labels in any
intervening code. But the same labels are used in any number of IF
constructs. There is no risk of conflict, if used correctly.
The ultimate barrier is one's viewpoint.
- Terry Pratchett, "The Dark Side of the Sun"