Sun Studio 12 Update 1: C User's Guide

2.12.2 __asm Keyword

The __asm keyword (note the initial double-underscore) is a synonym for the asm keyword. If you use asm, rather than __asm, and compile in -Xc mode, the compiler issues a warning. The compiler does not issue a warning if you use __asm in –Xc mode. The __asm statement has the form:


__asm("string");

where string is a valid assembly language statement.

The statement emits the given assembler text directly into the assembly file. A basic asm statement declared at file scope, rather than function scope, is referred to as a global asm statement. Other compilers refer to this as a toplevel asm statement.

Global asm statements are emitted in the order they are specified. That is, they retain their order relative to each other and maintain their position relative to surrounding functions.

At higher optimization levels, the compiler may remove functions that it believes are not referenced. Since the compiler will not know which functions are referenced from within global asms, it is possible that they may be removed inadvertently.

Note that extended asm statements, those which provide a template and operand specifications, are not allowed to be global. __asm and __asm__ are synonyms for the asm keyword and can be used interchangeably.