Incorrect translation of LDR pseudo instruction

Asked by Dan Lewis on 2017-04-12

I've discovered that the LDR pseudo instruction doesn't work as expected. My understanding is that the instruction:

      LDR R0,=constant // where "constant" is a number

Should be replaced by one of the following, depending on the value of the constant:

      MOV R0,constant
      MOVW R0,constant // may also be written MOV.W R0,constant
      MVN R0,~constant
      LDR R0,memref // where the constant has been stored separately in memory

None of these translations should modify the flags. Yet, for small positive constants as in:

       LDR R0,=1

It gets translated into:

       MOVS R0,1

which modifies the flags.

In the ARM documentation at, under the heading "LDR in Thumb code", it says:

"The LDR pseudo-instruction never generates a 16-bit flag-setting MOV instruction. "


Question information

English Edit question
GNU ARM Embedded Toolchain Edit question
No assignee Edit question
Last query:
Last reply:

Can you help with this problem?

Provide an answer of your own, or ask Dan Lewis for more information if necessary.

To post a message you must log in.