I am trying to pass a blank value to a macro funtion in GNU Assembly on x64, this function is supposed to add three value togather or just two according to if the first argument is blank, e.g.,
.macro foo1 t0, t1, t2 .ifnb t0 add \t0, \t1 .endif add \t1, \t2 .endm foo2: foo1 , %rax, %rbx foo1 %rax, %rbx, %rcx
But when I complie the above code, the gcc said
expecting operand before ','; got nothing because I call foo1 use the folloing format
foo1 , %rax, %rbx.
So I am confused about how to use
.ifnb pseudo-op, and how to pass a blank argument to a macro like foo1.
I tried to search in google, but I got few things about gnu assembly blank value. https://sourceware.org/binutils/docs/as/If.html
I also read GAS official docs but it also not mention how to use
.ifnb and no blank argument example was given for
The correct syntax for
.ifnb is as follows:
.macro foo1 t0, t1, t2 .ifnb \t0 ; <------ Note the backslash preceding the `t0` add \t0, \t1 .endif add \t1, \t2 .endm
You are getting a confusing error message pointing to the line of macro invocation, because it seem to be generated after the macro expansion to
add , %rax but still refer to the line in the original code.