AnsweredAssumed Answered

Mixing ASM and C Code in Kinetis K60

Question asked by Ruben Valls Blasco on Jun 2, 2014
Latest reply on Mar 19, 2018 by 涛 李

Hi all!

I am trying to implement the macros htons and htonl used for changing the endianness of 2 and 4 bytes words.

Those should be as fast as possible, so I wanted to implement them in ASM, since there exists the instructions for ARM which already do that: REV and REV16.


My question is: how can I implement this in a .c file (actually in a .h, since the functions will be defined as static inline)?


I.e: in my .h file:


//Declare the function static inlined, with code in ASM and register calling convention.

static inline __asm declspec(register_abi) uint32_t htonl(uint32_t x)


   rev r0, r0



All my attempts lead to syntax errors or linkage errors.


I am using CodeWarrior 10.6, and Kinetis K60 as processor


Any help is appreciated.

Best regards,