ARM VERSION 1.2 Computer Hardware User Manual


 
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