This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using inline assembly to store LR to C variable

I am trying to pull the data from the link register and save it to a c variable.  I could not find a structure to use to find the LR, so I am trying to use inline assembly to save it to a varibale.  Looking online, i tried doing the following:

int val;

asm("  mov r14,%0" : "=r" (val));

When I do that, i get an error saying it expected a ")".  When I try:

int val;

asm("  mov r14,val");

I get errors for undefined symbol and invalid operand.  What would be the right way to use inline assembly to write to a c variable?  Is there an easier way to save the link register in a variable?

Thanks

  • Kevin,

    Assume you're using the TI ARM compiler and not GCC or another compiler like IAR or Keil??   This is a compiler specific question...

    TI's compiler doesn't implement all of the GCC extensions.   The compiler manual (google SPNU151 to find it) lists the extensions supported/not supported in Table 5-5 section 5.15.1.  "Extended asm  / Assembler instructions with C Operands" is one of the unsupported extensions.

    I think you'll need to write an assembly routine as an ABI compilaint C function,  which would mean moving LR into R0 and then returning immediately.   Then try to get that function to inline to take out the overhead.   That's what I'd suggest trying anyway.

    Best Regards,

  • Unfortunately, this statement is incorrect.

    Anthony F. Seely said:
    try to get that function to inline to take out the overhead

    It is not possible to inline a call to a function that is implemented in assembly code.

    Thanks and regards,

    -George