| Creating a Combined C++/Assembly Language Project |
|
Updated 11/25/2002
Step 1: Create a C++ Project
Step 2: Create the C++ Source Module
Click on OK. When the empty main.cpp editing window appears, input the following C++ source code and save the file:
Notice how we included the function prototype for DoubleIt, along with the required extern and "C" qualifiers. The qualifiers are discussed in Section 12.3.4 in the book. Step 3: Add the ASM Source Module
(The Text File category also works, as long as you enter an .ASM extension when you name the file.) When the subr.asm editing window opens, input the following source code and save the file:
We chose not to use the INCLUDE Irvine32.inc directive here because DoubleIt doesn't call any library procedures. But we at least must identify the processor type (.586 = Pentium), the memory model (.model flat), and the language calling convention (C). Step 4: Assemble and Build the ProgramWith the subr.asm module as the active edit window, select Assemble 32-bit from the Tools menu. (Remember the cautionary statement at the beginning of this tutorial?) We will assume that the module assembled successfully. Select Add To Project... | Files from the Project menu. In the File name field of the Insert Files Into Project dialog window, enter the name subr.obj. Click on OK. The name subr.obj will appear in the list of files in the Workspace window after you click on its File View tab. (In case the window is not visible, select Workspace from the View menu.) Use the mouse to select the window containing main.cpp, and select Build Test1.exe from the Build menu. There should be no errors, but in case you have errors in the main.cpp file, fix them and try again. Step 5: Run the ProgramSelect Execute Test1.exe from the Build menu. The following output should appear in a console window:
If you try to run the program by selecting Start Debug | Go from the Build menu, the program output disappears so quickly that you cannot read it. On the other hand, if you press the F10 key to single-step through the program in the debugger, you can see the program's output in the MS-DOS window (see the icon on your status bar at the bottom of the screen). Tutorial finished.
|