4.2.4.2 Describing assembler instruction

With the CC-RH, assembler instruction can be described in the functions of a C source program.

(1)

#pragma directives

One of the #pragma directives to embed assembler instructions is #pragma inline_asm.

This treats the function itself as an assembler instruction only, and performs inline expansion at the call site.

 

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.

Specifying (size = numerical value) does not affect the result of compilation.

Example

-

C source

#pragma inline_asm      func_add
static int      func_add(int a, int b){
        add     r6, r7
        mov     r7, r10
}
void func(int *p){
        *p = func_add(10,20);
}

-

Output codes

_func:
prepare r20, 0
mov     r6, r20
movea   0x0014, r0, r7
mov     10, r6
add     r6, r7
mov     r7, r10

(2)

Notes for Use of #pragma inline_asm

-

Specify #pragma inline_asm before the definition of the function body.

-

Also generate external definitions of functions specified with #pragma inline_asm.

-

If you use a register to guarantee the entrance and exit of an inline function with embedded assembly, you must save and restore this register at the beginning and end of the function.

-

The compiler passes strings in #pragma inline_asm to the assembler as-is, without checking or modifying them.

-

Only positive integer constants are specifiable for (size = numerical value). Specifying a floating-point number or value less than 0 will cause an error.

-

If #pragma inline_asm is specified for a static function, then the function definition will be deleted after inline expansion.

-

Assembly code is targeted by the preprocessor. Caution is therefore needed when using #define to define a macro with the same name as an instruction or register used in assembly language (e.g. "MOV" or "r5").

-

Although it is possible to use comments starting with a hash ("#") in RH850 assembly language, if you use this comment, do not use # comments inside functions coded in assembly, because the preprocessor will interpret these as preprocessing directives.

-

If you write a label in a function coded in assembly, labels with the same name will be created for each inline expansion.
In this situation, use local labels coded in assembly. Although local labels have the same name in the assembly source, the assembler converts them to different names automatically.