I'm attempting to write inline assembly in GCC which writes a value in a #define to a register.
#define SOME_VALUE 0xDEADBEEF void foo(void) { __asm__("lis r5, SOME_VALUE@ha"); __asm__("ori r5, r5, SOME_VALUE@l"); } However, I get an error when I compile:
undefined reference to `SOME_VALUE'
Is there a way for the assembler to see the #define in the inline assembly?
I've solved it by doing the following:
#define SOME_VALUE 0xDEADBEEF __asm__(".equ SOME_VALUE, 0xDEADBEEF"); void foo(void) { __asm__("lis r5, SOME_VALUE@ha"); __asm__("ori r5, r5, SOME_VALUE@l"); } However, I really don't want to duplicate the value.
__asm__is taking a string as an argument. So think about macro stringifying the value/ concatenating strings.SOME_VALUEas an immediate on whatever architecture that is. Or just ask the compiler to put it inr5for you, withregister int foo asm("r5") = SOME_VALUE;and then use it as an input. Or if you don't care what register, then let the compiler pick.