This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: What's the best way to define local labels in an assembler macro?


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

is probably:

   .macro MACRO_A
   1:

   MACRO_B whatever

   jump 1b

   1:                      // A "jump 1f" in MACRO_B allows exit.
   .endm

The second "1:" demonstrates label re-use, and forward/backward
referencing.

Try invoking MACRO_A several times, and observe what happens in the
output listing.

> 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
ago:

   .altmacro

   .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.
   jmp \dest
   .endm

(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.

Erik

-- 
"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
was young!"
"Why, what did she tell you?"
"I don't know, I didn't listen!"
                     - Douglas Adams, "Hitchhiker's Guide to the Galaxy"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]