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-13<br />
AREA Tblock, CODE, READONLY ; Name this block of code<br />
num EQU 20 ; Set number of words to be copied<br />
ENTRY<br />
; Mark first instruction to execute<br />
header<br />
; The first instruction to call<br />
MOV sp, #0x400 ; Set up stack pointer (r13)<br />
ADR r0, start + 1 ; Processor starts in <strong>ARM</strong> state,<br />
BX r0 ; so small <strong>ARM</strong> code header used<br />
; to call Thumb main program<br />
CODE16<br />
; Subsequent instructions are Thumb<br />
start<br />
LDR r0, =src ; r0 =pointer to source block<br />
LDR r1, =dst ; r1 =pointer to destination block<br />
MOV r2, #num ; r2 =number of words to copy<br />
blockcopy<br />
LSR r3,r2, #2 ; Number of four word multiples<br />
BEQ copywords ; Less than four words to move?<br />
PUSH {r4-r7} ; Save some working registers<br />
quadcopy<br />
LDMIA r0!, {r4-r7} ; Load 4 words from the source<br />
STMIA r1!, {r4-r7} ; and put them at the destination<br />
SUB r3, #1 ; Decrement the counter<br />
BNE quadcopy ; ... copy more<br />
POP {r4-r7} ; Don't need these now-restore originals<br />
copywords<br />
MOV r3, #3 ; Bottom two bits represent number<br />
AND r2, r3 ; ...of odd words left to copy<br />
BEQ stop ; No words left to copy?<br />
wordcopy<br />
LDMIA r0!, {r3} ; load a word from the source and<br />
STMIA r1!, {r3} ; store it to the destination<br />
SUB r2, #1 ; Decrement the counter<br />
BNE wordcopy ; ... copy more<br />
stop MOV r0, #0x18 ; angel_SWIreason_ReportException<br />
LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit<br />
SWI 0xAB ; Thumb semihosting SWI<br />
AREA BlockData, DATA, READWRITE<br />
src DCD 1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4<br />
dst DCD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0<br />
END<br />
<strong>ARM</strong> DUI 0204BSC © 2002、 2003 <strong>ARM</strong> Limited 版 权 所 有 。 保 留 所 有 权 利 。 2-49