With .altmacro
, any parameter passed or default with a percent %
gets treated as an expression.
Sample usage:
.altmacro
.macro PERCENT x
mov $\x, %eax
.endm
mov $0, %eax
PERCENT %1+1
/* eax == 2 */
.macro PERCENT_DEFAULT x=%1+1
mov $\x, %eax
.endm
mov $0, %eax
PERCENT_DEFAULT 1
/* eax == 1 */
PERCENT_DEFAULT
/* eax == 2 */
To prevent that expansion from happening, we have to do as mentioned by mfbutner:
.altmacro
.macro PERCENT x
mov \x, %eax
.endm
PERCENT <%ebx>
.macro PERCENT_DEFAULT x=<%ebx>
mov \x, %eax
.endm
PERCENT_DEFAULT
Since this expansion happens only to arguments, not inside the macro itself, one alternative if we are sure that the argument is a register, is to put the percent inside the macro:
.macro PERCENT_ESCAPE_REG x
mov %x, %eax
.endm
mov $0, %eax
mov $1, %ebx
PERCENT_ESCAPE_REG ebx
/* eax == 1 */
But this has the downside that we cannot pass immediates like $1
anymore:
PERCENT_ESCAPE_REG $1
This is to me a huge turnoff to using .altmacro
, as it requires callers to use extra noise on every call...