This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Instruction width selection - forward/external reference

Hi,
I am learning the Thumb 2 instruction set and at the moment I am trying to understand when to use the instruction width specifier.
e.g.:

ldmia.w 	sp!,{r3,lr}

I understand sometimes it is necessary to make some instructions 32 bit wide because the content/addresses is/are not fitting into the 16 bit encoding.
But reading the ARM Keil explanation about it I am wondering what exactly is meant by internal/external reference?
And more precisely when I have to worry about adding .w and when not?
  • Hi ,

    I have moved your question to the Processors community as they may be best placed to answer your question.

  • In general, the assembler will take care. You only need to worry about it if you want to force a special instruction. I suggest to read the relevant reference manual as it lists all opcodes and the syntax.

  • In the case of using Branch instructions in assembly programming, if the branch target is in a different object file (i.e. extern), then you might need to specify 32-bit version of branch instructions as the branch offset might be larger than the range of a 16-bit branch instruction. If you do not add the .W suffix, the assembler might use a 16-bit branch instruction and then at linking stage the linker flag up an error saying that the branch operation cannot be handled by that 16-bit instruction.

    If the branch is forward and the branch target is marginally near the limit of a 16-bit branch instruction, you might need to specify a 32-bit branch instruction as well, as the first pass of the assembling process might not have accurate address offset (some instructions between the branch and the branch target might changed from 16-bit to 32-bit in the second pass).

    regards,

    Joseph