Inline assembler |
In computer programming, Inline assembler is a feature of some Compilers that allows very low level code written in Assembly Language to be embedded in a high level language like C programming language or Ada programming language.
This allows programmers to optimise a very performance-sensitive algorithm by sending individual commands to the computer s Central processing unit. It allows the use of particular CPU instructions that the compiler would not normally emit because they do not correspond easily to any high-level language constructs. Examples include Compare-and-swap and Test-and-set instructions which may be used to construct Semaphore_%28programming%29 or other synchronization and locking primitives, as well as specialized instructions such as those found in the Sparc Visual_Instruction_Set, Intel MMX and Streaming_SIMD_Extensions, and Motorola Altivec instruction set.
This example of inline assembler is from the D_programming_language and computes the tangent of x using the x86 s FPU instructions.
= Example =
// Compute the tangent of x real tan(real x) { asm { fld x[EBP] ; // load x fxam ; // test for oddball values fstsw AX ; sahf ; jc trigerr ; // x is NAN, infinity, or empty // 387 s can handle denormals SC18: fptan ; fstp ST(0) ; // dump X, which is always 1 fstsw AX ; sahf ; jnp Lret ; // C2 = 1 (x is out of range) // Do argument reduction to bring x into range fldpi ; fxch ; SC17: fprem1 ; fstsw AX ; sahf ; jp SC17 ; fstp ST(1) ; // remove pi from stack jmp SC18 ; } trigerr: return real.nan; Lret: ; }
= External links =
*[http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html GCC-Inline-Assembly-HOWTO] *[http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Inline-Assembler.html GNAT Inline Assembler]|
|