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 http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489i/Babbfdih.html, under the heading "LDR in Thumb code", it says:

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

Dan

Question information

Language:
English Edit question
Status:
Answered
For:
GNU ARM Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
2017-04-12
Last reply:
2017-04-25

Confirmed. A fix has been made in binutils and will make its way in our 2017Q2 release.

Thanks for the bug report.

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.