tags:

views:

101

answers:

4

how often used such kind of expression in c++

#ifdef __BORLANDC__

  #pragma argsused

#endif

and also there is given code for assembler code in c++

#ifdef __BORLANDC__

  #pragma argsused

#endif



#include <iostream>

using namespace std;



int main( int argc, char * argv[] )

{

    int Number1, Number2, Result;



    __asm

    {

        MOV Number1, 248 // Initialize Number1

        MOV Number2, 405 // Initialize Number2

        MOV EAX, Number1 // Put the value of Number1 in the EAX register

        ADD EAX, Number2 // Add the value of Number2 to the content of EAX

        MOV Result, EAX  // Put the content of EAX into Result

    }                    // That's it



    cout << "Number1 = " << Number1 << endl;

    cout << "Number2 = " << Number2 << endl;

    cout << "\nAfter adding Number1 to Number2," << endl;

    cout << "Result  = " << Result << endl;



    return 0;

}

how can i check if my c++ has assembler compiler?

+1  A: 

#ifdefs are often used as header guards. The usage of this constructs is much wider, i just mentioned the most basic one. As for "assembler compiler", i believe most C++ compilers which follows the standard should be able to handle it. See for example here.

PeterK
A: 

As far as I know, only Borland compilers recognize the __asm keyword. I don't think there is a standard way to write inline assembly in C or C++

Update: Just checked that, and turns out it's far from being true. Example for MS compiler: link text

Simon
Visual C++ uses the __asm keyword too.
jeffm
A: 

You must check compiler name by ifdef directive and read documentation about a support of assembler. Also check a platform and I know that VS C++ does not support assembler in 64-bits edition.

MaxFX
A: 

Its actually worse than that. Most C++ implementations will have some way to do assembly inserts. However, those are (obviously) not portable to other platforms, and depending on the instructions you use may not even be portable to every processor available for the platform they do work on.

T.E.D.