{"id":5534,"date":"2014-03-30T23:47:00","date_gmt":"2014-03-30T23:47:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/question-about-objective-c-calling-convention-and-argument-passing-on-arm-collection-of-common-programming-errors\/"},"modified":"2014-03-30T23:47:00","modified_gmt":"2014-03-30T23:47:00","slug":"question-about-objective-c-calling-convention-and-argument-passing-on-arm-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/question-about-objective-c-calling-convention-and-argument-passing-on-arm-collection-of-common-programming-errors\/","title":{"rendered":"Question about Objective C calling convention and argument passing on ARM-Collection of common programming errors"},"content":{"rendered":"<p>For functions that returns a simple type:<\/p>\n<pre><code>r0 = self (NSString)\nr1 = _cmd (@selector(stringWithFormat:))\nr2 = 1st argument (@\"%@, %@\")\nr3 = 2nd argument (@\"Hello\")\n<\/code><\/pre>\n<p>then the rest is placed on the stack:<\/p>\n<pre><code>[sp,#0] = 3rd argument (@\"World\")\n[sp,#4] = 4th argument (does not exist in your example)\n...\n<\/code><\/pre>\n<p>Of course, &#8220;argument&#8221; here means a 4-byte object. If the argument has &gt;4 bytes then it will be split out, e.g.<\/p>\n<pre><code>-[UIView initWithFrame:rect];\n\nr0 = self\nr1 = _cmd\nr2 = rect.origin.x\nr3 = rect.origin.y\n[sp,#0] = rect.size.width\n[sp,#4] = rect.size.height\n<\/code><\/pre>\n<p>The returned value (up to 16 bytes) will be placed in r0, r1, r2, r3.<\/p>\n<p>For functions that returns a struct: <code>r0<\/code> is used to store the pointer of the return value.<\/p>\n<pre><code>NSRange retval = [self rangeOfString:string options:options range:range]\n\nr0 = &amp;retval (of type NSRange*)\nr1 = self\nr2 = _cmd (@selector(rangeOfString:options:range:))\nr3 = string\n[sp,#0] = options\n[sp,#4] = range.location\n[sp,#8] = range.length\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>For functions that returns a simple type: r0 = self (NSString) r1 = _cmd (@selector(stringWithFormat:)) r2 = 1st argument (@&#8221;%@, %@&#8221;) r3 = 2nd argument (@&#8221;Hello&#8221;) then the rest is placed on the stack: [sp,#0] = 3rd argument (@&#8221;World&#8221;) [sp,#4] = 4th argument (does not exist in your example) &#8230; Of course, &#8220;argument&#8221; here means [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5534","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5534"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5534\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}