Keil Logo Arm Logo

Assembler User Guide

Instruction width selection in Thumb

Instruction width selection in Thumb

If you are writing Thumb code for ARMv6T2 or later processors, some instructions can have either a 16-bit encoding or a 32-bit encoding.

If you do not specify the instruction size, by default:

  • for forward reference LDR, ADR, and B instructions, the assembler always generates a 16-bit instruction, even if that results in failure for a target that could be reached using a 32-bit instruction.

  • for external reference LDR and B instructions, the assembler always generates a 32-bit instruction.

  • in all other cases, the assembler generates the smallest size encoding that can be output.

If you want to over-ride this behavior, you can use the .W or .N width specifier to ensure a particular instruction size. The assembler will fault if it cannot generate an instruction with the specified width.

The .W specifier is ignored when assembling to ARM code, so you can safely use this specifier in code that might assemble to either ARM or Thumb code. However, the .N specifier will be faulted when assembling to ARM code.

Show/hideSee also

Concepts
Reference

Assembler Reference:

Copyright © 2007-2008, 2011-2012 ARM. All rights reserved.ARM DUI 0379D
Non-ConfidentialID062912

Keil logo

Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.