Describing assembler instruction (#pragma inline_asm)


This specifies inline expansion of a function written in the assembly language.

[Function]

-

Performs inline expansion on functions coded in assembly and declared with #pragma inline_asm.

-

The calling conventions for an inline function with embedded assembly are the same as for ordinary function calls.

[Usage]

-

#pragma inline_asm is declared before the target functions.

#pragma inline_asm  [(]function-name [,...][)]

[Restrictions]

-

#pragma inline_asm should be specified before the definition of the function body.

-

An external definition is also generated for a function specified with #pragma inline_asm.

-

The compiler passes the character strings written in the functions specified with #pragma inline_asm to the assembler without change.

-

The codes written in assembly language are processed by the preprocessor. Therefore, special care must be taken when the same names as the instructions or registers used in the assembly language are defined as the names of macros with #define. When including iodefine.h, the function written in the assembly language should be written before inclusion of iodefine.h.

-

Assembler control instructions are not usable in assembly code for functions specified as inline_asm. In addition, only the directives listed below are usable. Specifying any other directive will lead to an error.

-

data definition/area reservation directives (.DB/.DB2/.DB4/.DB8/.DS)

-

macro directives (.MACRO/.IRP/.REPT/.LOCAL/.ENDM)

-

externally defined directive (.PUBLIC) [V1.04 or later]

-

In the .PUBLIC directive in the function specified with inline_asm, only the labels defined in the function specified with inline_asm can be used. Using any other labels will lead to errors.

 

When a label is written in an assembly-language function, labels having the same name are generated for the number of times the function is expanded inline. In this case, take any of the following actions.

-

Use a local label written in the assembly language. A local label has a single name in the assembly-language code, but the assembler automatically converts it into separate names.

See ".LOCAL" for local labels.

-

Ensure that an external label is expanded only in one location.

-

When calling an assembly-language function within the current source file, define the assembly-language function as static and call it only from a single location. Do not obtain the address of the assembly-language function.

-

When not calling an assembly-language function within the current source file, code the function as an external function.

[Example]

The following shows a sample C source code.

#pragma inline_asm func
void func(int x)
{
    movw !_a, ax
}
 
#pragma inline_asm func1
static void __near func1(void)  // When calling within the current file a function 
{                               // that includes an external label definition and is 
                                // specified with inline_asm, code it as a static 
                                // __near function.
    .PUBLIC _label1
    incw ax
_label1:
    decw ax
}
 
#pragma inline_asm func2
void func2(void)                // When not calling within the current file a 
{                               // function that includes an external label 
                                // definition and is specified with inline_asm,
                                // code it as an external function.
    .PUBLIC _label2
    decw ax
_label2:
    incw ax
}
 
void main(void){
    func(3);
    func1();                    // Calls the function that includes an external 
                                // label definition and is specified with inline_asm.
}

 

The following shows the assembly source output by compiler.

    .SECTION .textf,TEXTF
_func:
    .STACK _func = 4
    ._line_top inline_asm
    movw !_a, ax
    ._line_end inline_asm
    ret
_func2:
    .STACK _func2 = 4
    ._line_top inline_asm
    .PUBLIC _label2
    decw ax
_label2:
    incw ax
    ._line_end inline_asm
    ret
_main:
    .STACK _main = 4
    movw ax, #0x0003
    ._line_top inline_asm   ; Expanded code of func
    movw !_a, ax            ;
    ._line_end inline_asm   ;
    ._line_top inline_asm   ; Expanded code of func1
    .PUBLIC _label1         ;
    incw ax                 ;
_label1:                    ;
    decw ax                 ;
    ._line_end inline_asm   ;
    ret