The Inline Assembler

Now, it is time to describe the inline assembler. This is a powerful tool. You should only bear in mind that contemporary inline assemblers often provide limited capabilities in relation to support of new microprocessor commands. This is natural, because the development of a new version of developer tools, such as C++ Builder, requires considerably more time than the development of TASM. In the examples provided in Listings 20.9 and 20.10, coprocessor commands are used.

Listing 20.9: Using the ASM directive and coprocessor commands in a Pascal program
image from book
 program Project2; {$APPTYPE CONSOLE} uses     SysUtils; var     d:double; function soproc(f:double): double; var res:double; begin     asm         FLD f         FSIN         FSTP res     end;     soproc:=res ; end; begin     d:=-pi;     while (d<=pi) do     begin         writeln(d:10:2, '-', soproc(d):10:2);         d:=d+0.1;     end; end. 
image from book
 
Listing 20.10: Using the ASM directive and coprocessor commands in a C program (Borland C++ 5.0)
image from book
 #include <windows.h> #include <stdio.h> double soproc(double f); void main() {         double w = -3.14;         while(w<=3.14)         {                 printf("%f- %f\n", w, soproc(w));                 w = w + 0.1;         }         ExitProcess (0); } double soproc (double f) {         double d;         asm         {                 FLD f                 FSIN                 FSTP d         }         return d; } 
image from book
 


The Assembly Programming Master Book
The Assembly Programming Master Book
ISBN: 8170088178
EAN: 2147483647
Year: 2004
Pages: 140
Authors: Vlad Pirogov

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net