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
A subroutine is a block of code that performs a task based on some arguments and optionally returns a result. By convention, registers R0 to R3 are used to pass arguments to subroutines, and R0 is used to pass a result back to the callers. A subroutine that needs more than 4 inputs uses the stack for the additional inputs.
To call subroutines, use a branch and link instruction. The syntax is:
the subroutine code is executed you can use a
Calls between separately assembled or compiled modules must comply with the restrictions and conventions defined by the Procedure Call Standard for the ARM Architecture.
Example 8 shows a
Example 8. Add two arguments
AREA subrout, CODE, READONLY ; Name this block of code ENTRY ; Mark first instruction to execute start MOV r0, #10 ; Set up parameters MOV r1, #3 BL doadd ; Call subroutine stop MOV r0, #0x18 ; angel_SWIreason_ReportException LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit SVC #0x123456 ; ARM semihosting (formerly SWI) doadd ADD r0, r0, r1 ; Subroutine code BX lr ; Return from subroutine END ; Mark end of file