Path: csiph.com!weretis.net!feeder9.news.weretis.net!panix!.POSTED.localhost!not-for-mail From: Grant Edwards Newsgroups: comp.arch.embedded Subject: Re: gcc arm inline asm: how to output value for .set directive? Date: Thu, 3 Apr 2025 23:06:25 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: References: Injection-Date: Thu, 3 Apr 2025 23:06:25 -0000 (UTC) Injection-Info: reader1.panix.com; posting-host="localhost:::1"; logging-data="4560"; mail-complaints-to="abuse@panix.com" User-Agent: slrn/1.0.3 (Linux) Xref: csiph.com comp.arch.embedded:32407 On 2025-04-03, Grant Edwards wrote: > How do I convince ARM GCC's extended asm() to emit a value that can be > used in a .set directive? Here's a simplified example: > asm("\t.set foo_offset, %[off]" : : [off] "i" ( __builtin_offsetof(shm_t, foo) ) : ); That didn't work, because gcc emits #40 instead of 40: > 35 .set foo_offset, #40 I finally stumbled across some example code that showed me the answer. It's not the _constraint_ in the input operand list (the "i" above) that matters (I had tried all upper/lower ascii letters). You need a modifier in the _template_ string that references that input operand: asm("\t.set foo_offset, %c[off]" : : [off] "i" ( __builtin_offsetof(shm_t, foo) ) : ); The secret is the 'c' in "%c[off]" Now that I know what to look for, I found it in the manual https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Generic-Operand-Modifiers 6.11.2.8 Generic Operand Modifiers I had completely missed the difference between a qualifier and a modifier...