Slide 14.7: Linking to C/C++ (cont.)
Slide 14.9: Calling C/C++ functions (cont.)
Home

Calling C/C++ Functions


You can write assembly language programs that call C++ functions. There are at least a couple of reasons for doing so: When calling functions from the standard C/C++ library, you must start the program from a C/C++ main( ) procedure to allow library initialization code to run.

Function Prototypes
C++ functions called from assembly language code must be defined with the "C" and extern keywords. Here is the basic syntax:
   extern  "C"  funName( paramlist ) {
      ...   }
Here is an example:
   extern  "C"  int  askForInteger( ) {
      cout << "Please enter an integer:";
      // ...
   }
Rather than modifying every function definition, it's easier to group multiple function prototypes inside a block. Then you can omit extern and "C" from the function implementations:
   extern  "C" {
      int  askForInteger( );
      int  showInt( int value, unsigned outWidth );
      etc.
   }