[英]Clarifications on iOS Assembly Language
我正在研究Objective-C语言如何映射到Assembly。 我从iOS Assembly Tutorial中的教程开始 。
正在分析的代码段如下。
void fooFunction() {
int add = addFunction(12, 34);
printf("add = %i", add);
}
它被翻译成
_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}
关于汇编代码,我无法理解以下两点
->评论@ 1
作者说,由于r7
和lr
均为4字节,所以push
将堆栈减少8个字节。 好。 但是他还说, 这两个值与一条指令一起存储 。 这是什么意思?
->评论@ 6
movw r0, :lower16:(L_.str-(LPC1_0+4))
movt r0, :upper16:(L_.str-(LPC1_0+4))
作者说r0
将保存"add = %i"
的地址(可以在数据段中找到),但我并没有真正了解内存布局的样子。 他为什么用黑色虚线表示差异L_.str-(LPC1_0+4)
而不用红色表示差异(由我绘制)。
任何澄清将不胜感激。
编辑
我缺少将r7
推入堆栈的概念。 推动该价值意味着什么,它包含什么?
但是他还说这两个值与一条指令一起存储。 这是什么意思?
单个push
指令会将两个值都放入堆栈。
他为什么代表差异L_.str-(LPC1_0 + 4)
因为add r0, pc
隐式地增加了4个字节。 引用指令集参考 :
Add an immediate constant to the value from sp or pc, and place the result into a low register.
Syntax: ADD Rd, Rp, #expr
where:
Rd is the destination register. Rd mustbe in the range r0-r7.
Rp is either sp or pc.
expr is an expression that evaluates (at assembly time) to a multiple of 4 in the range 0-1020.
If Rp is the pc, the value used is: (the address of the current instruction + 4) AND &FFFFFFFC.
对于注释1:压入堆栈的两个值是存储在r7
和lr
中的值。
两个4字节值等于8字节。
对于注释6:标签LPC1_0
后跟指令
add r0, pc
这会将另外4个字节加到两个地址之间的差值中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.