I compile c code to arm with this site https://godbolt.org/
int F(int a, int b)
{
int c=0;
for(int i=0;i<=10;i++)
{
c+=a+b;
}
return c;
}
the result was
F(int, int):
str fp, [sp, #-4]!
add fp, sp, #0
sub sp, sp, #20
str r0, [fp, #-16]
str r1, [fp, #-20]
mov r3, #0
str r3, [fp, #-8]
mov r3, #0
str r3, [fp, #-12]
.L3:
ldr r3, [fp, #-12]
cmp r3, #10
bgt .L2
ldr r2, [fp, #-16]
ldr r3, [fp, #-20]
add r3, r2, r3
ldr r2, [fp, #-8]
add r3, r2, r3
str r3, [fp, #-8]
ldr r3, [fp, #-12]
add r3, r3, #1
str r3, [fp, #-12]
b .L3
.L2:
ldr r3, [fp, #-8]
mov r0, r3
sub sp, fp, #0
ldr fp, [sp], #4
bx lr
I saw here that parameters moved on the stack and not via registers.
I have 3 line that I not understand
add fp, sp, #0
sub sp, sp, #20
str r0, [fp, #-16]
- why fp get value= 0? I read about fp but I not sure I eral get it.
- why sp get down 20? I know it usualy to save plave for the local var, but why 20?
- why
str r0, [fp, #-16]I not get it
by the way, why the parameters hers pass in the stack and not on registers? thank you all