Writing ARM and Thumb Assembly Language

Note

The label used with ADR or ADRL must be within the same code section. The assembler faults references to labels that are out of range in the same section. The linker faults references to labels that are out of range in other code sections.

In Thumb state, ADR can generate word-aligned addresses only.

ADRL is not available in Thumb code. Use it only in ARM code.

Example 2-6 shows the type of code generated by the assembler when assembling ADR and ADRL pseudo-instructions. It is supplied as adrlabel.s in the examples\asm subdirectory of the ADS. Refer to Code examples on page 2-2 for instructions on how to assemble, link, and execute the example.

The instructions listed in the comments are the ARM instructions generated by the assembler.

 

 

 

 

 

Example 2-6

 

 

 

 

 

 

 

AREA

adrlabel, CODE,READONLY

 

 

 

 

ENTRY

 

; Mark first instruction to execute

Start

 

 

 

 

 

 

BL

func

; Branch

to subroutine

stop

MOV

r0, #0x18

; angel_SWIreason_ReportException

 

LDR

r1, =0x20026

; ADP_Stopped_ApplicationExit

 

SWI

0x123456

; ARM semihosting SWI

 

LTORG

 

; Create

a literal pool

func

ADR

r0, Start

; => SUB

r0, PC, #offset to Start

 

ADR

r1, DataArea

; => ADD

r1, PC, #offset to DataArea

 

; ADR

r2, DataArea+4300

; This would fail because the offset

 

 

 

; cannot

be expressed by operand2

 

 

 

; of an ADD

 

ADRL

r2, DataArea+4300

; => ADD

r2, PC, #offset1

 

 

 

;

ADD

r2, r2, #offset2

 

MOV

pc, lr

; Return

 

DataArea

SPACE

8000

; Starting at the current location,

 

 

 

; clears

a 8000 byte area of memory

 

 

 

; to zero

 

 

END

 

 

 

 

 

 

 

 

 

 

ARM DUI 0068B

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

2-31

Page 43
Image 43
ARM VERSION 1.2 manual Adr