Share via


The __asm Keyword in SHx Inline Assembly

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 an __asm call is invoked, its function prototype must be declared. The following code fragments show how to make an __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 an __asm declaration, the string argument is a null terminated character string consisting of one or more valid SH-3 or 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 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.

The following code fragment shows how to use multiple assembly language statements to write a program that prints out "Hello".

#include <stdio.h>
extern void __asm(const char *, ...);
main() {
   __asm(
      "jsr @R5; Call printf\n"
      "nop      ; Don't forget the delay slot"
      ,"Hello\n"
      ,printf
      );
}

See Also

Elements of the SHx __asm Block | __asm Restrictions in SHx Inline Assembly | Constants in SHx Inline Assembly | Symbols and Labels in SHx Inline Assembly | SHx Inline Assembly Parameters | SH-4 Mode Bits | Branching in SHx Inline Assembly

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.