; *********************************************************************** ; * * ; * Simple Subroutines (Function Calls) * ; * * ; *********************************************************************** ; Author: John Zaitseff ; Date: 9th September, 2002 ; Version: 1.3 ; This program contains simple subroutine calls (also known as a function ; calls). It illustrates the "bl" (branch and link) instruction, as well ; as the standard method of returning from such calls. .text .global _start _start: mov r0,#15 ; Set up parameters mov r1,#32 bl f_add ; Call the function "f_add"; result is in R0 mov r1,#5 ; Set up the second parameter ; (other parameter is still in R0) bl f_sub ; Call the function "f_sub exit: swi 0x11 ; Terminate the program f_add: ; Function "f_add" for addition ; A function (subroutine) and its caller need to agree on a "calling ; convention", a statement about what parameters are expected on entry ; (and in what registers or memory locations) and what is returned (and in ; what registers or memory locations). ; For the function "f_add", R0 and R1 on entry are the addends; on exit, ; R0 is the sum. add r0,r0,r1 ; Perform R0 := R0 + R1 mov pc,lr ; and return to the caller f_sub: ; Function "f_sub" for subtraction ; On entry, R0 is the minuend and R1 is the subtrahend. On exit, R0 is ; the difference. sub r0,r0,r1 ; Perform R0 := R0 - R1 mov pc,lr ; and return to the caller .end