6.7.2. THUMB

The THUMB directive instructs the assembler to interpret subsequent instructions as 32-bit Thumb-2 instructions or 16-bit Thumb instructions using new syntax. If necessary, it also inserts padding to align to the next halfword boundary.

Syntax

THUMB

Usage

In files that contain a mixture of ARM and Thumb code:

  • Use THUMB when changing from ARM state to Thumb state, if the following code uses ARM syntax.

  • Use CODE16 when changing from ARM state to Thumb state, if the following code uses old Thumb syntax (see CODE16).

  • Use ARM when changing from Thumb state to ARM state. ARM (or CODE32) must precede any ARM code (see ARM and CODE32).

THUMB does not assemble to an instruction that changes the state. It only instructs the assembler to assemble Thumb-2 or Thumb instructions as appropriate, and insert padding if necessary.

Example

This example shows how ARM and THUMB can be used to branch from ARM to Thumb instructions.

        AREA    ChangeState, CODE, READONLY
        ARM
                             ; This section starts in ARM state
        LDR     r0,=start+1  ; Load the address and set the
                             ; least significant bit
        BX      r0           ; Branch and exchange instruction sets
                             
                             ; Not necessarily in same section
        THUMB                ; Following instructions are Thumb-2

        GSthing        PROC

        B       {pc}+2 ; #0x8002
        B       {pc}+4 ; #0x8004
Copyright © 2002-2005 ARM Limited. All rights reserved.ARM DUI 0204F
Non-Confidential