关于目标C调用约定和参数传递的ARM问题 [英] Question about Objective C calling convention and argument passing on ARM

查看:143
本文介绍了关于目标C调用约定和参数传递的ARM问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何客观C运行时处理的参数,当我打电话像

I want to know how objective C runtime handle arguments when I call a objective C method like

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

有三个参数为这一目标调用C,它是如何相比,ARM系统上典型的方式工作。我所知道的寄存器R0,R1,R2,R3将举行第4个参数,如何有额外的参数?它是如何把它们在堆栈上,后来弹出他们?

There are three arguments for this objective C call, how does it work compared to typical way on a ARM system. I have known register r0, r1, r2, r3 will hold first 4 arguments, how about there are additional arguments? How does it put them on a stack and pop them later?

推荐答案

有关函数返回一个简单类型:

For functions that returns a simple type:

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

那么剩下的放在栈上:

then the rest is placed on the stack:

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

当然,说法在这里是指一个4字节的对象。如果参数有> 4个字节那么它将被拆分出来,例如

Of course, "argument" here means a 4-byte object. If the argument has >4 bytes then it will be split out, e.g.

-[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

The returned value (up to 16 bytes) will be placed in r0, r1, r2, r3.

对于返回结构功能: R0 是用来存储返回值的指针

For functions that returns a struct: r0 is used to store the pointer of the return value.

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

这篇关于关于目标C调用约定和参数传递的ARM问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆