How to write ARM assembly function which is calling from C

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

Hi Ganesh,

Did you managed to solve your problem? I am facing the same.

Regards,

Rick

Everything could be written in C to configure peripherals, even for drivers.

Check here, lot of exemples. http://www.siwawi.arubi.uni-kl.de/avr_p … index.html

Angelo

Hi Polux!

Indeed, you’re right, everything could be written in C.

What I am really in trouble with is the fact that I want to set GPIOs in less cycles as I can.

Suppose I want to shift bits, like an SPI feature. I guess the compiler would write more lines just for a “for(;;)”.

Actually, I want to make a software UART. But I want to call the assembly code through C code.

Cheers!

Rick

Nobody has mentioned here what compiler they are using.

The easiest way to optimize small sections of code is to look at the dissassembly of the code you want to optimize, cut it out and replace it with ASM codes inside the C program and inside it’s own C function. Writing a whole function in assembler can be dangerous if it takes parameters. This way you can let the compiler manage the function call the way it wants and not have to worry about it changing parameters from being on the stack to being in a register when you change optimizations.

You could also inline the assembly in a C function, almost every compiler supports this.

Sorry guys,

I am using IAR C/C++ compiler for the ARM processor.

I just received a suggestion from the IAR support and it is the same as Mark’s.

Using assembly inline, how can I access the local variables/registers ?

eg.:

unsigned char localvar;

localvar=0x0F;

asm(“MOV R0, localvar”);

Is this possible?

Thank you.

Here’s a good reference to use (should work for the IAR compiler):

http://www.ibiblio.org/gferg/ldp/GCC-In … HOWTO.html

Make sure that you’re either certain that the compiler is not using those registers you are changing, or save those register values and restore them after you are done with them.