Search code examples
armgnu-assembler

Comparing macro parameters in gnu asm (gas)


I'm trying to create macros for arm assembly (using GNU tools).

.macro FUNCTION     name, attrs
    .ifc    \attrs\(),"global"
        .global         \name
    .endif

    // other stuff
.endm

So macros FUNCTION myFunc, global can be evaluated with .global attribute. However, the marcro does not handle this attribute compare. Simply stated .if is never evaluated?

Is there a way to compare such string-like macro parameters?


Solution

  • Gas uses single quotes to denote strings and not double quotes.

    .ifc string1,string2

    Assembles the following section of code if the two strings are the same. The strings may be optionally quoted with single quotes. If they are not quoted, the first string stops at the first comma, and the second string stops at the end of the line. Strings which contain whitespace should be quoted. The string comparison is case sensitive.

    If there is no spaces or other parsing issue, as with global, you can just use the name as is without any quoting. So an acceptable solutions is,

    .macro FUNCTION     name, attrs
        .ifc    \attrs\(),global
            .global         \name
        .endif
    
        // other stuff
    .endm