The ARM Assembly The ARM Assembly: Stacks and Subroutines
The ARM Assembly The ARM Assembly: Stacks and Subroutines
Fall 2009
3 4
Standard ARM Calling Convention Example of Passing Parameters in Registers
` r15 is the program counter. SRAM_BASE EQU 0x40000000 saturate
` r14 is the link register. (The BL instruction, used in a AREA Passbyreg, CODE, READONLY
; subroutine saturate
; performs r2 = saturate32 (r0 << r1)
subroutine call, stores the return address in this ENTRY ; r0 = operand to be shifted
; r1 = shift amount m
register). LDR sp, =SRAM_BASE
; try out a positive case
; r2 = result
; r6 = scratch register
` r13 is chosen as the stack register. ; (this should saturate)
MOV r0, #0x40000000 STMIA sp!, {r6, lr}
` r12 is the Intra-Procedure-call scratch register. MOV r1, #8
BL saturate
MOV r6, #0x7FFFFFFF
MOV r2, r0, LSL r1
` r4 to r11: used to hold local variables. stop B stop ; if (
(r0
0 !
!= (
(r2
2 >> m))
))
` r0 to r3: used to hold argument values passed to TEQ r0, r2, ASR r1
; R2 = 0x7FFFFFFF^sign(r0)
a subroutine ... and also hold results returned EORNE r2, r6, r0, ASR #31
5 6