Everything
3.5 ASM statements

The __asm() function or #asm-#endasm is used to write assembly-language code within functions for the CA78K0R, whereas inline expansion is performed for the assembly-language functions declared in #pragma inline_asm for the CC-RL. The CcnvCA78K0R creates the __asm() function or the inline_asm function that executes assembly instructions in the range between #asm and #endasm at the beginning of the file and converts the program so that this function is called at the position where an assembly instruction is written.

 

The format of the CA78K0R is as follows.

#asm
  :    /* assembly-language code */
#endasm
__asm("assembly-language code");

The format of the CC-RL is as follows.

#pragma inline_asm [(] function-name [, … ] [)]
function-declaration {
  :    /* assembly-language code */
}

 

-

A tab is appended as an indent to the assembly-language code within the inline_asm function.

-

The function name to be created should be in the range between __inline_asm_func_00000 and __inline_asm_func_99999, and an error will occur if the number of functions exceeds 100,000.

-

If a label is in the range between #asm and #endasm or in the __asm function, the CcnvCA78K0R outputs a message. If a label is written in a function for which #pragma inline_asm is specified in the CC-RL, an error will occur at compilation. Therefore, if a label is in #asm-#endasm or the __asm function, the CcnvCA78K0R outputs a message. A label written in the assembly language needs to be changed to a local label to avoid a compile error. For details, see the user's manual of the CC-RL.

-

If double quotation marks (") are included in the target to be converted by the #define macro as shown in the example below, the inline_asm function cannot be generated from the __asm( ) function. In such a case, the CcnvCA78K0R outputs a message. The input file is directly output without its contents being converted. Perform conversion after expanding the macro in advance.

Example) #define MAC "nop"

__asm(MAC);

-

If control characters like '\n' or '\t' are included in a string in __asm( ), an assembly error will occur after conversion. Perform conversion after deleting the control characters in advance.

-

If a C-language comment ("/*") is included in the assembly-language comments (";") in the range between #asm and #endasm, the range of the comment is invalid. Perform conversion after deleting the comments in advance.

 

[Examples]

Pattern 1

Before conversion

void func()
{
  __asm("nop");
}

After conversion

#pragma inline_asm __inline_asm_func_00000
static void __inline_asm_func_00000(void)
{
    nop
}
 
void func()
{
    __inline_asm_func_00000();
}

Pattern 2

Before conversion

void func(void)
{
  #asm 
    nop
  #endasm
}

After conversion

#pragma inline_asm __inline_asm_func_00001
static void __inline_asm_func_00001(void)
{
    nop
} 
 
void func()
{
    __inline_asm_func_00001();
}

Pattern 3

Before conversion

#define ASM_NOP __asm("nop");

After conversion

#pragma inline_asm __inline_asm_func_00002
static void __inline_asm_func_00002(void)
{ 
  nop
} 
#define ASM_NOP __inline_asm_func_00002();

Pattern 4

(Error after conversion)

Before conversion

void func()
{
  __asm("\tnop");
}

After conversion

#pragma inline_asm __inline_asm_func_00003
static void __inline_asm_func_00003(void)
{
    \tnop
}
 
void func()
{
    __inline_asm_func_00003();
}