The __asm Keyword in SH-4 Inline Assembly (Windows CE 5.0)
The __asm keyword invokes the inline assembler, and can appear anywhere in a C or C++ statement. The compiler treats the __asm statement as an intrinsic function call.
Before a __asm call is invoked, its function prototype must be declared. The following code fragments show how to make a __asm prototype declaration in C++.
extern "C" { void __asm(const char *, ...); }
extern "C" { int __asm(const char *, ...); }
extern "C" { unsigned int __asm(const char *, ...); }
In C statements, the compiler requires a different form of declaration.
void __asm(const char *, ...);
int __asm(const char *, ...);
unsigned int __asm(const char *, ...);
In a __asm declaration, the string argument is a null terminated character string consisting of one or more valid SH-4 assembly source statements. The compiler passes any subsequent arguments to the assembly code described by the first string argument.
The following syntax shows the structure of an assembly source statement.
[<label>:] [<operation> [<operand(s)>]] [comment]
The following code example shows how to use an assembly source statement.
Label1: MOV.L@RO,R1 ;This is an example source statement
Multiple assembly-language instructions may be listed in a single __asm statement by using embedded newline characters (\n) as separators within the string argument. A comment can be included on any line, started with a semicolon.
Restrictions
A __asm line record can be any valid assembly operation code accepted by the stand-alone assembler. In addition, a __asm line record can contain a label definition or a comment as described in the previous sections. However, there are some coding restrictions:
- No directives except for .prolog are allowed in the __asm instruction stream. If the prolog end is not at the function start, it must be marked within a __asm statement using this directive. For more information on function prologs and epilogs, see
- No expansion of assembler instructions is performed. After scaling, immediate values must fit in the associated object code field for the instruction.
See Also
Elements of the SH-4 __asm Block
Send Feedback on this topic to the authors