This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Syntax to make .altmacro feature %EXPR work?
- From: Erik Christiansen <dvalin at internode dot on dot net>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: binutils at sourceware dot org
- Date: Tue, 9 Jan 2018 23:03:27 +1100
- Subject: Re: Syntax to make .altmacro feature %EXPR work?
- Authentication-results: sourceware.org; auth=none
- References: <20180106020917.GA3591@ratatosk> <e3eea927-4805-fa00-a503-2e72c2d39c6b@redhat.com>
On 08.01.18 11:51, Nick Clifton wrote:
> Hi Erik,
>
> > But the % operator then appears to be running past the '&' separator, to
> > swallow all of the rest of the line.
>
> Actually no. The problem is that you cannot generate symbol names via
> string concatenation. So:
>
> .equ "fred" "0" , 42
>
> does not generate a symbol called fred0. What you need is nested macros,
> as macro arguments can be evaluated inside strings. Like this:
>
> .macro make_sym prefix value
> .equ "fred\prefix", \value
> .endm
>
> .altmacro
> .macro foo n hah
> i = 0
> .rept \n
> make_sym %(i) \hah&+1
> i = i + 1
> .endr
> .endm
>
> foo 3 42
>
> Cheers
> Nick
Grateful thanks, Nick, for the insight. The solution works like a charm,
so long as I lose the quotes. (They produced an error message: "unknown
escape '\p' in string; ignored" - promptly fixed. The different
behaviour might be due to my old avr-as, perhaps.)
Thanks again,
Erik