Syntax to make .altmacro feature %EXPR work?

Erik Christiansen dvalin@internode.on.net
Tue Jan 9 12:03:00 GMT 2018


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



More information about the Binutils mailing list