courses:embedded_system:loop_ex1
数据块的复制
请将源数据区 Src 中的18个字单元复制到目标数据区 Dst,要求以4个字为单位,最后不足4字时可以以字为单位复制。
- Copy_Data.S
num_of_words EQU 18 AREA CopyData, CODE, READONLY ENTRY start LDR R0, = Src LDR R1, = Dst MOV R2, #num_of_words LDR SP, =0x40001000 MOVS R3, R2, LSR #2 BEQ Copy_Words STMFD SP!, {R5-R8} Copy_4Words LDMIA R0!, {R5-R8} STMIA R1!, {R5-R8} SUBS R3, R3, #1 BNE Copy_4Words LDMFD SP!, {R5-R8} Copy_Words ANDS R2, R2, #3 BEQ Stop Copy_Word LDR R3, [R0], #4 STR R3, [R1], #4 SUBS R2, R2, #1 BNE Copy_Word Stop B Stop LTORG Src DCD 1,2,3,4,5,6,7,8,9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x12 Dst DCD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 END