Question about assigning a call to Objective-C and passing arguments to ARM

I want to know how the objective arguments to the C execution descriptor are when I call the C object method like

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

There are three arguments for this object call to C, how it works compared to the normal method on an ARM system. I knew that the register r0, r1, r2, r3 would contain the first 4 arguments, what about the extra arguments? How does he push them onto the stack and pop them later?

+7
assembly compiler-construction arm iphone calling-convention
source share
1 answer

For functions returning a simple type:

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

then the rest are pushed onto 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, for example.

 -[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 return value (up to 16 bytes) will be placed in r0, r1, r2, r3.


For functions that return a structure: r0 used to store the return value pointer.

 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 
+18
source share

All Articles