I'm investigating a little bit on how Objective-C language is mapped into Assembl. I've started from a tutorial found at iOS Assembly Tutorial.
The code snippet under analysis is the following.
void fooFunction() {
int add = addFunction(12, 34);
printf("add = %i", add);
}
It is translated into
_fooFunction:
@ 1:
push {r7, lr}
@ 2:
movs r0, #12
movs r1, #34
@ 3:
mov r7, sp
@ 4:
bl _addFunction
@ 5:
mov r1, r0
@ 6:
movw r0, :lower16:(L_.str-(LPC1_0+4))
movt r0, :upper16:(L_.str-(LPC1_0+4))
LPC1_0:
add r0, pc
@ 7:
blx _printf
@ 8:
pop {r7, pc}
About the assembly code, I cannot understand the following two points
-> Comment @1
The author says that push
decrements the stack by 8 byte since r7
and lr
are of 4byte each. Ok. But he also says that the two values are stored with the one instruction. What does it mean?
-> Comment @6
movw r0, :lower16:(L_.str-(LPC1_0+4))
movt r0, :upper16:(L_.str-(LPC1_0+4))
The author says the that r0
will hold the address of the "add = %i"
(that can be find in the data segment) but I don't really get how the memory layout looks like. Why does he represent the difference L_.str-(LPC1_0+4)
with the dotted black line and not with red one (drawn by me).
Any clarifications will be appreciated.
Edit
I'm missing the concept of pushing r7
onto the stack. What does mean to push that value and what does it contain?