The assembly code around calling the function square generated by LLVM would perhaps look something like below (in thumb instruction set):
0xe0d42: ldr r0, #42 //number_to_square 0xe0d44: bl 0xf0b00 //address of square function
The square function itself would look something like below:
0xf0b00: sub sp, #4 //subtract sp to claim space for 4 bytes (function locals) 0xf0b02: str r0, [sp] //store the parameter (number_to_square) in r0 on stack in sp 0xf0b04: ldr r0, [sp] //load the parameter in r0 0xf0b06: ldr r1, [sp] //load the same parameter in r1 0xf0b08: muls r0, r1, r0 //multiply both and store results in r0, update cpsr flags 0xf0b0a: add sp, #4 //sp = sp+4, destroy the local space we created 0xf0b0c: bx lr //branch back to caller
Floating point arguments are passed in floating point registers s(d)0-s(d)4 depending on whether single precision (C type float) or double precision (C type double) arguments are being passed around. Floating point results are returned in s(d)0.Stack arguments are pushed in the same order as function parameters.
Hope this helps you when you are looking at that crash report from iOS or a dump from another ARM platform7.
1I do not have the latest iPhone. So we would be looking at iPhone 4, ARMv7, 32-bit architecture on Cortex-A8 based Apple A4. The new iPhone 5’s are on ARMv8, 64-bit.
2Xcode Version 5.0.2 (5A3005)
3Note that this is equivalent of info registers command in GDB.
4So if you were having fun with the low bits in pointer addresses, be careful on ARM, since bit 0 has special meaning
5If you want to see things running in ARM mode, OSSpinLockUnlock$shim is a UIKit function that runs in ARM mode.
6This is very similar to x64 calling convention with RAX in place of r0 for return and RCX,RDX,R8,R9 for register arguments
7AAPCS, the Procedure Call Standard for ARM Architecture, is the latest ABI from ARM