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: Syntax to make .altmacro feature %EXPR work?


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


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