| ||||||||
Technical Support On-Line Manuals Assembler User Guide | Load addresses to a register using ADR
The NoteThe label used with The available range of addresses for the
Example 10 shows ARM code that implements a jump table. Here, the Example 10. Implementing a jump table (ARM)
AREA Jump, CODE, READONLY ; Name this block of code
ARM ; Following code is ARM code
num EQU 2 ; Number of entries in jump table
ENTRY ; Mark first instruction to execute
start ; First instruction to call
MOV r0, #0 ; Set up the three parameters
MOV r1, #3
MOV r2, #2
BL arithfunc ; Call the function
stop
MOV r0, #0x18 ; angel_SWIreason_ReportException
LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
SVC #0x123456 ; ARM semihosting (formerly SWI)
arithfunc ; Label the function
CMP r0, #num ; Treat function code as unsigned integer
BXHS lr ; If code is >= num then simply return
ADR r3, JumpTable ; Load address of jump table
LDR pc, [r3,r0,LSL#2] ; Jump to the appropriate routine
JumpTable
DCD DoAdd
DCD DoSub
DoAdd
ADD r0, r1, r2 ; Operation 0
BX lr ; Return
DoSub
SUB r0, r1, r2 ; Operation 1
BX lr ; Return
END ; Mark the end of this file
In Example 10, the function
The jump table is implemented with the following instructions and assembler directives:
| |||||||
| ||||||||