23.10.2014 Views

RealView - ARM Information Center

RealView - ARM Information Center

RealView - ARM Information Center

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

示 例 2-12<br />

AREA Block, CODE, READONLY ; name this block of code<br />

num EQU 20 ; set number of words to be copied<br />

ENTRY<br />

; mark the first instruction to call<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 />

MOV sp, #0x400 ; Set up stack pointer (r13)<br />

blockcopy MOVS r3,r2, LSR #3 ; Number of eight word multiples<br />

BEQ copywords ; Less than eight words to move?<br />

STMFD sp!, {r4-r11} ; Save some working registers<br />

octcopy LDMIA r0!, {r4-r11} ; Load 8 words from the source<br />

STMIA r1!, {r4-r11} ; and put them at the destination<br />

SUBS r3, r3, #1 ; Decrement the counter<br />

BNE octcopy ; ... copy more<br />

LDMFD sp!, {r4-r11} ; Don't need these now - restore<br />

; originals<br />

copywords ANDS r2, r2, #7 ; Number of odd words to copy<br />

BEQ stop ; No words left to copy?<br />

wordcopy LDR r3, [r0], #4 ; Load a word from the source and<br />

STR r3, [r1], #4 ; store it to the destination<br />

SUBS r2, 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 0x123456 ; <strong>ARM</strong> 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-47

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

Saved successfully!

Ooh no, something went wrong!