Directives Reference

7.7.3CODE16 and CODE32

The CODE16 directive instructs the assembler to interpret subsequent instructions as

16-bit Thumb instructions. If necessary, it also inserts a byte of padding to align to the next halfword boundary.

The CODE32 directive instructs the assembler to interpret subsequent instructions as 32-bit ARM instructions. If necessary, it also inserts up to three bytes of padding to align to the next word boundary.

Syntax

CODE16

CODE32

Usage

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

Use CODE16 when changing from ARM state to Thumb state. CODE16 must precede any Thumb code.

Use CODE32 when changing from Thumb state to ARM state. CODE32 must precede any ARM code.

CODE16 and CODE32 do not assemble to instructions that change the state. They only instruct the assembler to assemble Thumb or ARM 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

 

CODE32

 

 

 

 

 

; 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 Thumb

start

MOV

r1,#10

; Thumb instructions

7-54

Copyright © 2000, 2001 ARM Limited. All rights reserved.

ARM DUI 0068B

Page 336
Image 336
ARM VERSION 1.2 manual CODE16 and CODE32