Syntax to make .altmacro feature %EXPR work?

Nick Clifton nickc@redhat.com
Mon Jan 8 11:51:00 GMT 2018


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



More information about the Binutils mailing list