iphone - 关于 Objective C 调用约定和在 ARM 上传递参数的问题

标签 iphone compiler-construction assembly arm calling-convention

我想知道当我调用像这样的 Objective C 方法时 Objective C 运行时如何处理参数

[NSString stringWithFomat:@"%@, %@", @"Hello", @"World"]

此 objective-c 调用有三个参数,与 ARM 系统上的典型方式相比,它是如何工作的。我知道寄存器 r0、r1、r2、r3 将保存前 4 个参数,那么还有其他参数怎么样?它如何将它们放入堆栈并稍后弹出它们?

最佳答案

对于返回简单类型的函数:

r0 = self (NSString)
r1 = _cmd (@selector(stringWithFormat:))
r2 = 1st argument (@"%@, %@")
r3 = 2nd argument (@"Hello")

然后将剩余的部分放入堆栈:

[sp,#0] = 3rd argument (@"World")
[sp,#4] = 4th argument (does not exist in your example)
...

当然,这里的“参数”是指4字节的对象。如果参数有 >4 个字节,那么它将被拆分,例如

-[UIView initWithFrame:rect];

r0 = self
r1 = _cmd
r2 = rect.origin.x
r3 = rect.origin.y
[sp,#0] = rect.size.width
[sp,#4] = rect.size.height

返回值(最多16个字节)将被放置在r0、r1、r2、r3中。

<小时/>

对于返回结构体的函数:r0用于存储返回值的指针。

NSRange retval = [self rangeOfString:string options:options range:range]

r0 = &retval (of type NSRange*)
r1 = self
r2 = _cmd (@selector(rangeOfString:options:range:))
r3 = string
[sp,#0] = options
[sp,#4] = range.location
[sp,#8] = range.length

关于iphone - 关于 Objective C 调用约定和在 ARM 上传递参数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2442278/

相关文章:

iphone - 如何通过点击 detailDiclosureButton 获取详细信息

c++ - 编译器中保护/私有(private)继承的实现

assembly - 32位汇编的64位指令

java - ASM 方法访问者可以与接口(interface)一起使用吗?

windows - 为什么这段代码能让我检测到调试器?

iphone - iOS 版 AIR : create enterprise App without the certificate

iphone - 应用程序 "failed to resume in time"并挂起

c - 为什么 C 有这些奇怪的翻译限制(第 2.2.4.1 节)?

c# - 词法分析器和解析器之间的通信

iphone - NSHost花费了很长时间