Mixed C and Assembly style coding for K60 on Code warrior 10.3

cancel
Showing results for 
Search instead for 
Did you mean: 

Mixed C and Assembly style coding for K60 on Code warrior 10.3

Jump to solution
1,525 Views
nasreenshaikh
Contributor III

HI,

I am trying to write a delay function for k60 in codewarrior 10.3 using the __asm directive.The compiler gives me an error as follows

"expected '(' before '{' token" .The help manual for Codewarrior 10.3 states that

"To ensure that the C/C++ compiler recognizes the asm keyword, you must clear the ANSI Keywords Only checkbox in the C/C++ Language panel. "

But the C/C++ Build properties do not have an option for this particular setting.

In the Build properties panel under the ARM LTD windows GCC C compiler -->Miscellaneous-->Language standard If I change it from Compiler default to ISO C9 -ansi teh error related to asm directive goes away . But the rest of my C code throws up Multiple errors.

I know that asm directive is  ansi keyword. How do I enable my compiler to accept ANSI keywords?   


Labels (1)
0 Kudos
1 Solution
259 Views
nasreenshaikh
Contributor III

Thank You Carlos

The asm directive does work with the GCC compiler. The problem was that I was using the syntax of HCS08 compiler as i was working on a project which uses both HCS08 and Kinetis K60. After using the correct syntax for GCC the error goes away. below is the function which I have written .

void delay10us(uint16_t us)

{

//uint16_t cnt;

asm volatile(

       

        "\n"

        "L_dl1%=:"   "\n\t"

        "mov r1, %1" "\n\t"

        "L_dl2%=:"   "\n\t"

        "sub r1, #1" "\n\t"

        "bne L_dl2%=""\n\t"

        "mov r2, %0" "\n\t"

        "sub r2, #1"     "\n\t"

        "bne L_dl1%=""\n\t"

        :: "r" (us), "r" (delay_count_us)

         );

View solution in original post

0 Kudos
2 Replies
259 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Nasreen,

GCC compiler will recognize asm directive by default, below you can see a very simple example. using asm instructions in a c file and also calling an assembly subroutine in a .s file.

in main.c

#include "derivative.h"

extern void _add();

 

int main(void)

{

 

asm ("mov r0, #0x0A");

asm ("mov r1, #0x03");

asm ("bl _add"); //using assembly code

}

in add.s

.global _add 

.text

.align 4 

_add:

 

  add r0, r0, r1

  bx lr

 

Hope this helps!

Carlos

260 Views
nasreenshaikh
Contributor III

Thank You Carlos

The asm directive does work with the GCC compiler. The problem was that I was using the syntax of HCS08 compiler as i was working on a project which uses both HCS08 and Kinetis K60. After using the correct syntax for GCC the error goes away. below is the function which I have written .

void delay10us(uint16_t us)

{

//uint16_t cnt;

asm volatile(

       

        "\n"

        "L_dl1%=:"   "\n\t"

        "mov r1, %1" "\n\t"

        "L_dl2%=:"   "\n\t"

        "sub r1, #1" "\n\t"

        "bne L_dl2%=""\n\t"

        "mov r2, %0" "\n\t"

        "sub r2, #1"     "\n\t"

        "bne L_dl1%=""\n\t"

        :: "r" (us), "r" (delay_count_us)

         );

0 Kudos