Hi, I am writing the driver for the spi. I have written the c part but for configuring the spi i should have the basic macro for memory mapped IO. I am trying to write assembly code for memory mapped IO. I have written the Arm assembly code like ... str1copy: LDRB r2, [r1],#1 And i am compiling by using the "arm-none-eabi". Then i can get the object file for assembly. Then i have written one "C" code where i am calling this assembly. That code is like this one....... #include <stdio.h> extern void str1copy(char *d, const char *s); int main() { const char *srcstr = "First string - source "; char dststr[] = "Second string - destination "; str1copy(dststr,srcstr); return (0); } And i compiled this by using the "arm-none-eabi". and i got the object file. But while Linking these two obj file by using the "arm-none-eabi_ld". I am getting this error. test.o: In function `main': test.c:(.text+0x2c): undefined reference to `memcpy' test.c:(.text+0x3c): undefined reference to `str1copy' Can any one please help me, how can i write the assembly code to get proper driver. Thanks in advance Ganesh
I'm quite sure that you don't need assembly for this, I guess you can do everything in C...
If you really want that(writing a pure assembly function) you should
write something like a normal function and place asm("LDRB r2,
[r1],#1"); inside the body. You might need the "naked" attribute too(you
should look in the generated code after this and see what it was
generated to be sure it doesn't mess up your application).
> test.c:(.text+0x2c): undefined reference to `memcpy'
You are missing here some libraries, you need to link also liba.c and
libm.c.
Hope it helps!
Lucian
P.S. Or you cand use the strcpy provided with the compiler ;-).
> liba.c and libm.c.
Correction libc.a and libm.a
C compiler inserts a _ in front of all symnbols, the assembler probably does not. _str1copy: if you use a C++ compiler, get used with much more funny name mangling (parameters are suffixed with the name). Your compiler might require obfuscated syntax when declaring (if you ever wrote dll for windows, you would know __export __DLL __pascal __winApi are important in the declaration of each function) Your compiler might require something close to extern _asm_linkage_ void str1copy(char *dst, char *src) or also, possibly extern "C" void str1copy(char *dst, char *src) Check the doc of your compiler. As suggested in this thread of mails, use assembly inside C function if you use gnu C compiler. It looks like that: void str1copy(char *dst, char *src) { _asm_ { \n mov r0, %0 \n mov r1, %1 \n ..... \n" : : "=r"(dst), "=r" (src): (memory) (r0) (r1)}; } Browse the wen for similar code, and read the gnu documentation about the _asm_ parameters. They are hardware specific.
Ganesh Prasad wrote: >... > But while Linking these two obj file by using the "arm-none-eabi_ld". I > am getting this error. Don't use the linker directly, used the frontend (arm-none-eabi-gcc) for linking. Using ld directly may cause unneeded trouble. > test.o: In function `main': > test.c:(.text+0x2c): undefined reference to `memcpy' As already mentioned: link with libc (and libgcc) using options -lc (-lgcc) > test.c:(.text+0x3c): undefined reference to `str1copy' Try .global str1copy str1copy: > Can any one please help me, how can i write the assembly code to get > proper driver. >... There might be no need to use assembly-language. The strcpy in newer versions of the newlib (the libc in CS G++ and other packages) includes a rather fast implementation for strcpy. Pierre wrote: >... >if you use a C++ compiler, get used with much more funny name mangling >(parameters are suffixed with the name). >... Yes, for C++, but this should not be an issue when using "pure" C and assembler files.
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.