0

I want to use a global variable in inline assembly.

asm(" LDR R0,g_TsInitStackPointerAddress");

Here g_TsInitStackPointerAddress is a global variable. While compiling its not showing any error .

But while linking it shows the following error

[elxr] (error) out of range: 0x1001326 (unsigned) didn't fit in 12 bits while performing relocation type R_ARM_POOL (4) at address 0x10013e0 from InitStack+0x20 (drv.o(.text)+0x1a4), to g_TsInitStackPointerAddress+0x0 ((COMMON)+0xb6)

Here My function name is InitStack and File name is drv. I am unable to understand the error.

Processor Used : Cortex R4
Compiler : Greenhills

Jay
  • 24,173
  • 25
  • 93
  • 141
suraj
  • 283
  • 3
  • 5
  • 13
  • It seems your variable is too small? Maybe you should check the size of R0 register and the size of your variable. – RedX Jun 26 '12 at 09:17

1 Answers1

1

Got the Solution

__asm("g_TsInitStackPointerAddress_a: DCD g_TsInitStackPointerAddress ");

Give this statement inside that function then it'll take that variable in the inline assembly

suraj
  • 283
  • 3
  • 5
  • 13
  • I believe a safer way to do this is to use the `ldr=` pseudo-instruction, as seen here: http://blogs.arm.com/software-enablement/251-how-to-load-constants-in-assembly-for-arm-architecture/ This will let the assembler decide where to place the constant pool (e.g., after the end of the function), rather than forcing you to place it manually yourself. – Quuxplusone Feb 05 '13 at 19:20