1

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?

2
  • a1 is a register name; can you try another label to see if it works? Did you mean a label or the value 0xa1? 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. Apr 20, 2016 at 12:35
  • Since you are using gcc, how about using extended asm and listing a1 as an input? Apr 21, 2016 at 2:30

1 Answer 1

2

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.

1
  • Thanks all for help. Adding -ffunction-sections flags works for me so far, but .ltorg does not work.
    – wxie
    Apr 21, 2016 at 3:04

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.