Subroutines calls

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:

    BL  destination

where destination is usually the label on the first instruction of the subroutine.

destination can also be a PC-relative expression.

The BL instruction:

After the subroutine code is executed you can use a BX LR instruction to return.


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 subroutine, doadd, that adds the values of two arguments and returns a result in R0.

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

Show/hideSee also

  • B, BL, BX, BLX, and BXJ

  • Procedure Call Standard for the ARM Architecture specification, http://infocenter/help/topic/com.arm.doc.ihi0042-

Copyright © 2010-2011 ARM. All rights reserved.ARM DUI 0473C