Writing ARM and Thumb Assembly Language
ARM DUI 0068B
Copyright © 2000, 2001 ARM Limited. All rights reserved.
2-37
An LDR Rd, =label example: string copying
Example 2-10 shows an ARM code routine that overwrites one string with another
string. It uses the
LDR
pseudo-instruction to load the addresses of the two strings from a
data section. The following are particularly significant:
DCB
The
DCB
directive defines one or more bytes of store. In addition to integer
values,
DCB
accepts quoted strings. Each character of the string is placed
in a consecutive byte. Refer to
DCB
on page 7-18 for more information.
LDR/STR
The
LDR
and
STR
instructions use post-indexed addressing to update their
address registers. For example, the instruction:
LDRB r2,[r1],#1
loads r2 with the contents of the address pointed to by r1 and then
increments r1 by 1.
Example 2-10 String copy
AREA StrCopy, CODE, READONLY
ENTRY ; Mark first instruction to execute
start LDR r1, =srcstr ; Pointer to first string
LDR r0, =dststr ; Pointer to second string
BL strcopy ; Call subroutine to do copy
stop MOV r0, #0x18 ; angel_SWIreason_ReportException
LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
SWI 0x123456 ; ARM semihosting SWI
strcopy
LDRB r2, [r1],#1 ; Load byte and update address
STRB r2, [r0],#1 ; Store byte and update address
CMP r2, #0 ; Check for zero terminator
BNE strcopy ; Keep going if not
MOV pc,lr ; Return
AREA Strings, DATA, READWRITE
srcstr DCB "First string - source",0
dststr DCB "Second string - destination",0
END
Содержание Developer Suite
Страница 10: ...Preface x Copyright 2000 2001 ARM Limited All rights reserved ARM DUI 0068B ...
Страница 110: ...Assembler Reference 3 32 Copyright 2000 2001 ARM Limited All rights reserved ARM DUI 0068B ...
Страница 185: ...ARM Instruction Reference ARM DUI 0068B Copyright 2000 2001 ARM Limited All rights reserved 4 75 Example MSR CPSR_f r5 ...
Страница 238: ...Thumb Instruction Reference 5 44 Copyright 2000 2001 ARM Limited All rights reserved ARM DUI 0068B ...
Страница 282: ...Vector Floating point Programming 6 44 Copyright 2000 2001 ARM Limited All rights reserved ARM DUI 0068B ...
Страница 360: ...Index Index 6 Copyright 2000 2001 ARM Limited All rights reserved ARM DUI 0068B ...