ARM inline asm: exit system call with value read from memory
<h1>Problem</h1>
<p>I want to execute the exit system call in ARM using inline assembly on a Linux Android device, and I want the exit value to be read from a location in memory.</p>
<h1>Example</h1>
<p>Without giving this extra argument, a macro for the call looks like:</p>
<pre><code>#define ASM_EXIT() __asm__(&quot;mov     %r0, #1\n\t&quot; \
                           &quot;mov     %r7, #1\n\t&quot; \
                           &quot;swi     #0&quot;)
</code></pre>
<p>This works well.
To accept an argument, I adjust it to:</p>
<pre><code>#define ASM_EXIT(var) __asm__(&quot;mov     %r0, %0\n\t&quot; \
                              &quot;mov     %r7, #1\n\t&quot; \
                              &quot;swi     #0&quot;          \
                              :                     \
                              : &quot;r&quot;(var))
</code></pre>
<p>and I call it using:</p>
<pre><code>#define GET_STATUS() (*(int*)(some_address)) //gets an integer from an address

ASM_EXIT(GET_STATUS());
</code></pre>
<h1>Error</h1>
<blockquote>
<p>invalid 'asm': operand number out of range</p>
</blockquote>
<p>I can't explain why I get this error, as I use one input variable in the above snippet (%0/var). Also, I have tried with a regular variable, and still got the same error.</p>