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: Nick Clifton <nickc at redhat dot com>
- To: Erik Christiansen <dvalin at internode dot on dot net>, binutils at sourceware dot org
- Date: Mon, 8 Jan 2018 11:51:25 +0000
- Subject: Re: Syntax to make .altmacro feature %EXPR work?
- Authentication-results: sourceware.org; auth=none
- References: <20180106020917.GA3591@ratatosk>
Hi Erik,
> Attempting to generate three symbols, fred0, fred1, fred2, is thwarted
> by errors, despite various guesses at legal %EXPR syntax:
> .altmacro
>
> .macro foo n hah
> i = 0
> .rept \n
> .equ fred%(i)& , \hah&+i
> i = i + 1
> .endr
> .endm
>
> foo 3 42
>
> The error message is still:
> Error: expected comma after "fred"
> 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