The assembly code around calling the function square looks like the following:
 
 


0x83d0:   mov    r0, #42 //number_to_square
0x83d4:   bl     0x8390  //address of square function

The square function itself looks like the following2:

0x8390:  push {r11} //save previous r11
0x8394:  add r11, sp, #0 //save current sp in r11
0x8398:  sub sp, sp, #12 //claim stack space for 12 bytes (locals)
0x839c:  str r0, [r11, #-8] //store first argument (r0) in local at r11-8
0x83a0:  ldr r3, [r11, #-8] //r3 = [r11-8] = number_to_square
0x83a4:  ldr r2, [r11, #-8] //r2 = [r11-8] = number_to_square
0x83a8:  mul r3, r2, r3 //multiply both and store results in r3
0x83ac:  mov r0, r3 //r0 = function return = number_to_square**2
0x83b0:  add sp, r11, #0 //sp = r11, destroy the local space we created
0x83b4:  pop {r11} //switch to the r11 value when we entered this fn
0x83b8:  bx lr //branch back to caller

One thing3 to note here is that r11 is being used as the frame pointer in the sense that the function prologue saves older r11 in stack and makes new r11 point to that stack location. Subsequently locals are accessed at negative offsets from r11. This is exactly how x86 standard frame pointer is setup using ebp register. Such usage of r11 register is certainly a platform/toolchain choice rather than driven by ARM processor architecture4.

Tagged with →  
Share →

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop us a note so we can take care of it!

Visit our friends!

A few highly recommended friends...

Set your Twitter account name in your settings to use the TwitterBar Section.