ARM VERSION 1.2 User Manual

Page 44

Advertising
background image

Writing ARM and Thumb Assembly Language

2-32

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

ARM DUI 0068B

Implementing a jump table with ADR

Example 2-7 on page 2-33 shows ARM code that implements a jump table. It is
supplied as

jump.s

in the

examples\asm

subdirectory of ADS. Refer to Code examples on

page 2-2 for instructions on how to assemble, link, and execute the example.

The

ADR

pseudo-instruction loads the address of the jump table.

In the example, the function

arithfunc

takes three arguments and returns a result in r0.

The first argument determines which operation is carried out on the second and third
arguments:

argument1=0

Result = argument2 + argument3.

argument1=1

Result = argument2 – argument3.

The jump table is implemented with the following instructions and assembler
directives:

EQU

Is an assembler directive. It is used to give a value to a symbol. In this
example it assigns the value 2 to

num

. When

num

is used elsewhere in the

code, the value 2 is substituted. Using

EQU

in this way is similar to using

#define

to define a constant in C.

DCD

Declares one or more words of store. In this example each

DCD

stores the

address of a routine that handles a particular clause of the jump table.

LDR

The

LDR pc,[r3,r0,LSL#2]

instruction loads the address of the required

clause of the jump table into the pc. It:

multiplies the clause number in r0 by 4 to give a word offset

adds the result to the address of the jump table

loads the contents of the combined address into the program
counter.

Advertising