6.7.3. CODE16

The CODE16 directive instructs the assembler to interpret subsequent instructions as 16-bit Thumb instructions using old Thumb syntax. If necessary, it also inserts a byte of padding to align to the next halfword boundary.

Syntax

CODE16

Usage

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

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

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

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

CODE16 does not assemble to instructions that change the state. It only instructs the assembler to assemble Thumb instructions as appropriate, and insert padding if necessary.

Example

This example shows how CODE16 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

        CODE16               ; Following instructions are old Thumb
start   MOV     r1,#10       ; old Thumb instructions
Copyright © 2002-2005 ARM Limited. All rights reserved.ARM DUI 0204F
Non-Confidential