Search code examples
assemblyarmkeil

Literal Pool too Distant?


I'm writing code in ARM assembly language on the Freescale Freedom KL46Z board in the Keil uVision 5 environment. My code is quite lengthy, but in the main part of the code, whenever I try to load (LDR) a constant or variable, I get this error: error: A1284E: Literal pool too distant, use LTORG to assemble it within 4KB I have no idea what this means or how to fix it. The spots where the errors occur are all on similar instructions. For example, the first error is on an instruction that reads: LDR R1,=Time where Time is defined as: Time SPACE 4 That instance was a variable but it also happens on defined constants. Can anyone help me figure out how to fix this error?


Solution

  • The error message explains more or less what you need to do. Insert an LTORG directive into your assembly code somewhere within 4096 bytes of line giving the error message. The LTORG statement must be in the same section as your code and it must not be on a code path that might be executed. It results in the insertion of constants (literals) into the section that will cause a crash or otherwise misbehave if executed.

    A good place is either is after end of the function (or before the function's entry label) that gives the error. If that's still more than 4K away then you need to find an unconditional branch or return instruction in your function that you can put it after. If there's no such instruction, then you'll have to insert an unconditional branch instruction that does nothing but jumps over an LTORG statement somewhere in your code.