Search code examples
assemblyarminline-assemblycpu-registers

assembly arm - how do I read back a register value and store that in a plain c variable


I need to read a register (r9) into a variable.

I have this

 pxTopOfStack[9-4] = 0x20000000;  // Set the task's initial R9 value

0x20000000 is stored in R9.

how could I inline this in arm assembly? I can set r9 in assembly as follows:

__asm volatile ("LDR r9, = 0x20000000");

but how would I set a plain C variable in inline assembly?

pseudo code

__asm volatile ("MOV pxTopOfStack[9-4], R9"); // just trying to illustrate what I am looking for

Solution

  • Copy pasted an example from developer.arm and modified it. Seems to work!

    __asm ("MOV %[result], R9"
        : [result] "=r" (pxTopOfStack[9-4])
      );