How can I use external definitions such as LONG_MIN and LONG_MAX in ARM assembler code?
Say my_arm.h looks like this:
int my_arm(int foo);
Let's say I have my_main.c as follows:
... #include <limits.h> #include "my_arm.h" ... int main (int argc, char *argv[]) { int foo=0; ... printf("My arm assembler function returns (%d)\n", my_arm(foo)); ... }
And my_arm.s looks like this:
.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
The second in the last line, I'm not sure how to boot correctly, I vaguely remember reading somewhere that I needed to define LONG_MAX in .global, but I can no longer find a link to a working example.
I am compiling with arm-linux-gnueabi-gcc version 4.3.2
===================
UPDATE: rate offers! Unfortunately, I am still having syntax issues.
First I made a small header file mylimits.h (now in the same directory as .S)
#define MY_LONG_MIN 0x80000000
in my_arm.S I added the following:
... .include "mylimits.h" ... ldr r7, =MY_LONG_MIN @ when it was working it was ldr r7, =0x80000000 ...
Two problems with this approach.
First, the biggest problem: the MY_LONG_MIN character is not recognized ... so something else is wrong.
Secondly: the syntax for .include does not allow me to include <limits.h> , I would add that it seems a bit kludgy in mylimits.h, but I suppose this is normal :)
Any pointers?
I have access to the ARM Systems Developers Guide Designing and Optimizing System Software [2004] and the ARM Architecture Reference Guide [2000], my goal is XScale-IXP42x Family rev 2 (v5l) though.