Assembler User GuideConventions and feedback Overview of the Assembler Overview of the ARM Architecture Structure of Assembly Language Modules Writing ARM Assembly Language Unified Assembler Language Subroutines calls Load immediates into registers Load immediate values using MOV and MVN Load 32-bit values to a register using MOV32 Load immediate 32-bit values to a register using L Literal pools Load addresses into registers Load addresses to a register using ADR Load addresses to a register using ADRL Load addresses to a register using LDR Rd, =label Other ways to load and store registers Load and store multiple register instructions Load and store multiple instructions available in Stack implementation using LDM and STM Stack operations for nested subroutines Block copy with LDM and STM Memory accesses Read-Modify-Write procedure Optional hash Use of macros Test-and-branch macro example Unsigned integer division macro example Instruction and directive relocations Symbol versions Frame directives Exception tables and Unwind tables Assembly language changes after RVCTv2.1 Condition Codes Using the Assembler Symbols, Literals, Expressions, and Operators VFP Programming
Load addresses to a register using LDR Rd, =label
The assembler converts an
Example 11 shows how this works.
The instructions listed in the comments are the ARM instructions generated by the assembler.
Example 11. Loading using LDR Rd, =label
AREA LDRlabel, CODE,READONLY ENTRY ; Mark first instruction to execute start BL func1 ; Branch to first subroutine BL func2 ; Branch to second subroutine stop MOV r0, #0x18 ; angel_SWIreason_ReportException LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit SVC #0x123456 ; ARM semihosting (formerly SWI) func1 LDR r0, =start ; => LDR R0,[PC, #offset into ; Literal Pool 1] LDR r1, =Darea + 12 ; => LDR R1,[PC, #offset into ; Literal Pool 1] LDR r2, =Darea + 6000 ; => LDR R2, [PC, #offset into ; Literal Pool 1] BX lr ; Return LTORG ; Literal Pool 1 func2 LDR r3, =Darea + 6000 ; => LDR r3, [PC, #offset into ; Literal Pool 1] ; (sharing with previous literal) ; LDR r4, =Darea + 6004 ; If uncommented produces an error ; as Literal Pool 2 is out of range BX lr ; Return Darea SPACE 8000 ; Starting at the current location, ; clears a 8000 byte area of memory ; to zero END ; Literal Pool 2 is out of range of ; the LDR instructions above
Example 12 shows an
ARM code routine that overwrites one string with another string.
It uses the
Example 12. 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 SVC #0x123456 ; ARM semihosting (formerly 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