Question about Objective C calling convention and argument passing on ARM

你离开我真会死。 提交于 2019-12-03 07:29:47

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)
...

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

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


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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!