23.10.2014 Views

RealView - ARM Information Center

RealView - ARM Information Center

RealView - ARM Information Center

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

编 写 <strong>ARM</strong> 和 Thumb 汇 编 语 言<br />

示 例 2-7 <strong>ARM</strong> 代 码 跳 转 表<br />

AREA Jump, CODE, READONLY ; Name this block of code<br />

CODE32<br />

; Following code is <strong>ARM</strong> code<br />

num EQU 2 ; Number of entries in jump table<br />

ENTRY<br />

; Mark first instruction to execute<br />

start<br />

; First instruction to call<br />

MOV r0, #0 ; Set up the three parameters<br />

MOV r1, #3<br />

MOV r2, #2<br />

BL arithfunc ; Call the function<br />

stop MOV r0, #0x18 ; angel_SWIreason_ReportException<br />

LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit<br />

SWI 0x123456 ; <strong>ARM</strong> semihosting SWI<br />

arithfunc<br />

; Label the function<br />

CMP r0, #num ; Treat function code as unsigned integer<br />

MOVHS pc, lr ; If code is >= num then simply return<br />

ADR r3, JumpTable ; Load address of jump table<br />

LDR pc, [r3,r0,LSL#2] ; Jump to the appropriate routine<br />

JumpTable<br />

DCD DoAdd<br />

DCD DoSub<br />

DoAdd ADD r0, r1, r2 ; Operation 0<br />

MOV pc, lr ; Return<br />

DoSub SUB r0, r1, r2 ; Operation 1<br />

MOV pc, lr ; Return<br />

END<br />

; Mark the end of this file<br />

<strong>ARM</strong> DUI 0204BSC © 2002、 2003 <strong>ARM</strong> Limited 版 权 所 有 。 保 留 所 有 权 利 。 2-35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!