How to write an assembly function?

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write an assembly function?

823 Views
Contributor I

Hello.

I am developing an embedded system with S32DS and I have a problem.

I have to write an assembly function as below:

asm volatile void OSPendSVException (void)
{

add sp, sp, #(9*4)
pop {pc}

bx lr
}

__asm void OSPendSVException1(void)
{

add sp, sp, #(9*4)
pop {pc}

bx lr
}

__asm__ void OSPendSVException2(void)
{

add sp, sp, #(9*4)
pop {pc}

bx lr
}

When compiling, the three functions above all have errors as below. 

无标题.png

I wonder to know how to write assembly function in S32DS.

Thank you very much.

Labels (1)
Tags (3)
0 Kudos
3 Replies

19 Views
Contributor I

Hello Jiri. Thank you very much for the help.

In the document about ARM and GCC, there are methods about how to write incline assembly code in C function.

My problem is that the whole function should be written as assembly function instead of some statements are written in assembly code.

This problem is in using the AutoSAR OS provided by NXP. In Os_hw_core_compiler.h file, there are some functions as below:

OSASM OSDWORD OSGETSTACKPOINTER_ (void)
{
mr r3, r1
}

The micro OSASM is defined as:

#if defined(OSDIABPPC)
#define OSASM __asm volatile
#endif /* defined(OSDIABPPC) */

#if defined(OSCWPPC)
#define OSASM asm
#endif /* defined(OSCWPPC) */

#if defined(OSGHSPPC)
#define OSASM asm
#endif /* defined(OSGHSPPC) */

In S32DS, I could not figure out how to define to OSASM  write a whole assembly function.

Please help me about above problem.

Thank you very much.

Have a nice work.

0 Kudos

19 Views
NXP Employee
NXP Employee

Hi, 

I'm afraid that gcc doesn't have such functionality. You can use only inline assembly. 

You can move your existing assembly code into .S file in S32DS project and call it from C code. 

Jiri

0 Kudos

19 Views
NXP Employee
NXP Employee

Hi, 

in S32DS you can use GNU inline assembly syntax. For more details you can look here:

http://www.ic.unicamp.br/~celio/mc404-s2-2015/docs/ARM-GCC-Inline-Assembler-Cookbook.pdf 

Jiri

0 Kudos