Text as parameter in inline assembly (ARM)?

263 views Asked by At

Is there a way to put plain text in inline assembly (ARM)? My problem is reading banked registers. The syntax is (r11 of user mode):

mrs r0, r11_usr

The problem is the "usr"-part.

I tried:

#define READ_REG_MODE(retvar, rg, mode) \
    asm volatile (\
    "mrs %[reg], r%c[rn]_%c[mod]\n\t"\
    :[reg] "=r" (retvar)\
    :[rn]"I"(rg), [mod]"X"("mode"):\
    )

with and without quotations both in this macro and in the macro-call. With [mod]"X"("mode") I got:

Error: selected processor does not support requested special purpose register -- `mrs r0,r11_.LC0'

1

There are 1 answers

0
Notlikethat On BEST ANSWER

This doesn't actually need to get anywhere near the assembler - it's something the C preprocessor can handle all by itself using the "stringification" # operator:

#define READ_REG_MODE(retvar, rg, mode) \
    asm volatile (\
    "mrs %[reg], r%c[rn]_" #mode "\n\t"\
    :[reg] "=r" (retvar)\
    :[rn]"I"(rg):\
    )