Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use C defines in ARM assembler
    text
    copied!<p>How can I use external defines such as LONG_MIN and LONG_MAX in ARM assembler code?</p> <p>Let's say my_arm.h looks like this:</p> <pre><code>int my_arm(int foo); </code></pre> <p>Let's say I have a my_main.c as follows:</p> <pre><code>... #include &lt;limits.h&gt; #include "my_arm.h" ... int main (int argc, char *argv[]) { int foo=0; ... printf("My arm assembler function returns (%d)\n", my_arm(foo)); ... } </code></pre> <p>And my_arm.s looks like this:</p> <pre><code> .text .align 2 .global my_arm .type my_arm, %function my_arm: ... ADDS r1, r1, r2 BVS overflow ... overflow: LDR r0, LONG_MAX @ this is probably wrong, how to do it correctly? BX lr @ return with max value </code></pre> <p>The second to last line, I am not sure how to load correctly, I vaguely remember reading somewhere, that I had to define LONG_MAX in .global, but can't find the link to a working example anymore.</p> <p>I am compiling with arm-linux-gnueabi-gcc version 4.3.2</p> <p>==================</p> <p>UPDATE: Appreciate the suggestions! Unfortunately, I am still having trouble with syntax.</p> <p>First, I made a little header file mylimits.h (for now in same dir as .S)</p> <pre><code>#define MY_LONG_MIN 0x80000000 </code></pre> <p>in my_arm.S i added the following:</p> <pre><code>... .include "mylimits.h" ... ldr r7, =MY_LONG_MIN @ when it was working it was ldr r7, =0x80000000 ... </code></pre> <p>Two problems with this approach.</p> <p>First the biggest problem: the symbol MY_LONG_MIN is not recognized...so something is still not right</p> <p>Second: syntax for .include does not let me include <code>&lt;limits.h&gt;</code>, I would have to add that in mylimits.h, seems a bit kludgy, but I suppose, that is ok :)</p> <p>Any pointers?</p> <p>I have access to ARM System Developer’s Guide Designing and Optimizing System Software[2004] and ARM Architecture Reference Manual[2000], my target is XScale-IXP42x Family rev 2 (v5l) though.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload