I am trying to compile this inline code for armv4t chip,
asm ("LDR R2, =a1");
gcc replies that
invalid literal constant: pool needs to be closer
I tried to move a1 near the function, but still the same error.
How to fix this error?
Just stolen from the ARM site (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0041c/Babbfdih.html):
The offset from the pc to the value in the literal pool must be less than 4KB. You are responsible for ensuring that there is a literal pool within range. See LTORG directive for more information.
so possibly the variable a1
is defined somewhere outside of this 4k, this is what the assembler sees as invalid so it generates the error message.
There is a lot more info at http://www.freertos.org/FreeRTOS_Support_Forum_Archive/February_2006/freertos_ARM_Error_invalid_literal_constant_pool_nee_1448037.html and ARM + gcc: don't use one big .rodata section
Some other sources (http://www.mikrocontroller.net/topic/68111 - German) suggest that the flag -ffunction-sections
should be added to the compiler.
a1
is a register name; can you try another label to see if it works? Did you mean a label or the value0xa1
? You can use,asm("ldr r2,=a1\nb 1f\n .ltorg\n 1:\n")
which should always work but usually you don't need this.