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: [gas] Label inside macro


On 08.06.11 21:00, Robert Uhl wrote:
> 
> Is it possible to make the label only visible inside the macro?
> Or is it possible to use the parameter as a label inside the macro?

Both. Mike Frysinger's suggestion is the simplest intra-macro local
labelling method. (If you need to go backwards in the macro, use 1b,
etc.)

Regarding the second question, here is a test macro which I wrote some
time ago. It demonstrates three ways to achieve local labelling in gas
macros, one of them using a parameter:

   .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

Usage:
   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.

All three worked well for me at the time.

Have fun with macros. They can be made to do more than is documented in
any detail, but it may be wise to archive a copy of the gas version
used [1], since I remember reading here that gas is intended to support gcc,
not those of us who play merry hell with macros, so there could
eventually be bitrot in dark corners, AIUI.


Erik

[1] But you're probably doing that already. ;-)

-- 
It is common sense to take a method and try it. If it fails, admit it
frankly and try another. But above all, try something.
                                              - Franklin D. Roosevelt


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