* [gas] Label inside macro
@ 2011-06-08 19:00 Robert Uhl
2011-06-08 19:33 ` David Daney
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Robert Uhl @ 2011-06-08 19:00 UTC (permalink / raw)
To: binutils
Hi,
I wrote the following macro and use it 256 times with the
parameter intnr 0...255.
.macro SPRINGBOARD intnr
cmpq $0, (counter_running)
je dont_count # interrupt counter disabled
push $\intnr
call countinterrupt
add $8, %rsp # remove intnr from stack
dont_count:
jmp *(originalhandler + \intnr * 8)
.align 16
.endm
Of course gas complains about the label dont_count:
"Error: symbol `dont_count' is already defined".
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?
I tried already "dont_count_\intr:" and "dont_count_\intr :" as a label
but gas shows: "Error: invalid character '(' in mnemonic"
I use "GNU assembler version 2.21 (x86_64-suse-linux) using BFD version
(GNU Binutils; openSUSE 11.4) 2.21".
Kind regards,
Robert
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gas] Label inside macro
2011-06-08 19:00 [gas] Label inside macro Robert Uhl
@ 2011-06-08 19:33 ` David Daney
2011-06-08 20:01 ` Mike Frysinger
2011-06-09 10:00 ` Erik Christiansen
2 siblings, 0 replies; 6+ messages in thread
From: David Daney @ 2011-06-08 19:33 UTC (permalink / raw)
To: Robert Uhl; +Cc: binutils
On 06/08/2011 12:00 PM, Robert Uhl wrote:
> Hi,
>
> I wrote the following macro and use it 256 times with the
> parameter intnr 0...255.
>
>
> .macro SPRINGBOARD intnr
> cmpq $0, (counter_running)
> je dont_count # interrupt counter disabled
>
> push $\intnr
> call countinterrupt
> add $8, %rsp # remove intnr from stack
>
> dont_count:
> jmp *(originalhandler + \intnr * 8)
> .align 16
> .endm
>
>
> Of course gas complains about the label dont_count:
> "Error: symbol `dont_count' is already defined".
>
> 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?
>
> I tried already "dont_count_\intr:" and "dont_count_\intr :" as a label
> but gas shows: "Error: invalid character '(' in mnemonic"
>
Look at:
http://sourceware.org/binutils/docs-2.21/as/Symbol-Names.html
Under the 'Local Labels' section, it explains how to do what you want.
David Daney
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gas] Label inside macro
2011-06-08 19:00 [gas] Label inside macro Robert Uhl
2011-06-08 19:33 ` David Daney
@ 2011-06-08 20:01 ` Mike Frysinger
2011-06-08 21:00 ` Robert Uhl
2011-06-09 10:00 ` Erik Christiansen
2 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2011-06-08 20:01 UTC (permalink / raw)
To: binutils; +Cc: Robert Uhl
[-- Attachment #1: Type: Text/Plain, Size: 1150 bytes --]
On Wednesday, June 08, 2011 15:00:13 Robert Uhl wrote:
> .macro SPRINGBOARD intnr
> cmpq $0, (counter_running)
> je dont_count # interrupt counter disabled
>
> push $\intnr
> call countinterrupt
> add $8, %rsp # remove intnr from stack
>
> dont_count:
> jmp *(originalhandler + \intnr * 8)
> .align 16
> .endm
>
>
> Of course gas complains about the label dont_count:
> "Error: symbol `dont_count' is already defined".
>
> 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?
>
> I tried already "dont_count_\intr:" and "dont_count_\intr :" as a label
> but gas shows: "Error: invalid character '(' in mnemonic"
David pointed you at the right documentation, but i'll just post an answer
since ive done more gas macro writing than i care to admit ...
try:
dont_count_\()\intr\():
and if that doesnt work, just use local labels like so:
...
je 1f;
...
1:
...
unless you have good reason for the symbols showing up in the compiled object,
i'd suggest you use the latter anyways
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gas] Label inside macro
2011-06-08 20:01 ` Mike Frysinger
@ 2011-06-08 21:00 ` Robert Uhl
2011-06-08 22:28 ` Mike Frysinger
0 siblings, 1 reply; 6+ messages in thread
From: Robert Uhl @ 2011-06-08 21:00 UTC (permalink / raw)
To: binutils
The label with \intnr doesn't work (why?), i get
"Error: invalid character '(' in mnemonic" again,
but with the local label everything is fine.
Thank you, Mike and David!
On 08.06.2011 22:01, Mike Frysinger wrote:
> try:
> dont_count_\()\intr\():
>
> and if that doesnt work, just use local labels like so:
> ...
> je 1f;
> ...
> 1:
> ...
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gas] Label inside macro
2011-06-08 21:00 ` Robert Uhl
@ 2011-06-08 22:28 ` Mike Frysinger
0 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2011-06-08 22:28 UTC (permalink / raw)
To: binutils; +Cc: Robert Uhl
[-- Attachment #1: Type: Text/Plain, Size: 475 bytes --]
On Wednesday, June 08, 2011 16:59:35 Robert Uhl wrote:
> The label with \intnr doesn't work (why?), i get
> "Error: invalid character '(' in mnemonic" again,
looking at some code ive written, this seems to work for me:
.macro pushr maxr:req
...
_push_r\maxr:
...
.endm
...
pushr 7
this creates a "_push_r7" label
i also have code that does:
.macro _pushrp maxr:req, maxp:req
...
_push_r\maxr\()_p\maxp:
...
.endm
...
_pushrp 4, 5
this creates a "_push_r4_p5" label
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gas] Label inside macro
2011-06-08 19:00 [gas] Label inside macro Robert Uhl
2011-06-08 19:33 ` David Daney
2011-06-08 20:01 ` Mike Frysinger
@ 2011-06-09 10:00 ` Erik Christiansen
2 siblings, 0 replies; 6+ messages in thread
From: Erik Christiansen @ 2011-06-09 10:00 UTC (permalink / raw)
To: binutils
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-06-09 10:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-08 19:00 [gas] Label inside macro Robert Uhl
2011-06-08 19:33 ` David Daney
2011-06-08 20:01 ` Mike Frysinger
2011-06-08 21:00 ` Robert Uhl
2011-06-08 22:28 ` Mike Frysinger
2011-06-09 10:00 ` Erik Christiansen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).