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?
Solved! Go to Solution.
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)
);
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
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)
);