Using the Development Studio or Visual Workbench with MASMLast reviewed: July 22, 1997Article ID: Q106399 |
4.00
WINDOWS
kbenv
The information in this article applies to:
SUMMARYThe Developer Studio that ships with Visual C++, 32-bit Edition, version 4.0, does not support assembler source files by default. That is, the Developer Studio does not associate any special significance to .ASM files without being informed otherwise. However, there are several viable options, namely custom build rules, which enable the creation of projects that depend directly upon assembler source files. The remainder of this article discusses four methods for adding .ASM files to a Visual C++ project. The methods are:
1. Using custom build rules; 2. Modifying a VWB makefile and using it as an external makefile; 3. Using an external makefile to assemble the assembly modules and then using an internal makefile for the main program, and 4. Creating an option on the VWB Tools menu to assemble each assembly module as needed.Of these methods, the use of custom build rules receives special attention. This powerful construct debuts in Visual C++ version 4.0. By utilizing a custom build rule, a project can invoke MASM on a per file basis to assemble .ASM files. The resulting object modules can then be linked into the desired target.
MORE INFORMATION
Method 1Using Visual C++ 4.0 Developer Studio, the following provides sample code and a step-by-step example of how to create a simple console application, CAPP, that requires MASM (ML.EXE) to assemble one of its source files. Note that the sample code for this example was borrowed from KB article Q104644, Passing C Arrays to MASM by Reference.
Method 1: Sample Code - C Module
/* Filename: CMAIN.C */ #include <stdio.h>#ifdef __cplusplus extern "C" { #endif
void MasmSub (char *, short *, long *);#ifdef __cplusplus } #endif
char chararray[4] = "abc";short shortarray[3] = {1, 2, 3}; long longarray[3] = {32768, 32769, 32770};
void main( void ){ printf ("%s\n", chararray); printf ("%d %d %d\n", shortarray[0], shortarray[1], shortarray[2]); printf ("%ld %ld %ld\n", longarray[0], longarray[1], longarray[2]); MasmSub (chararray, shortarray, longarray); printf ("%s\n", chararray); printf ("%d %d %d\n", shortarray[0], shortarray[1], shortarray[2]); printf ("%ld %ld %ld\n", longarray[0], longarray[1], longarray[2]);}
Method 1: Sample Code - ASM Module; Filename: MASMSUB.ASM ; Assemble options needed for ML: /c /Cx /coff .386 .MODEL flat, C .CODE MasmSub PROC uses esi, \ arraychar:PTR, \ arrayshort:PTR, \ arraylong:PTR mov esi, arraychar ; Load ESI with the address of the char array. mov BYTE PTR [esi], "x" ; Since a char is 1 byte long, each mov BYTE PTR [esi+1], "y" ; successive element can be accessed mov BYTE PTR [esi+2], "z" ; by adding 1 more to esi. mov esi, arrayshort; Load ESI with the address of the short array. add WORD PTR [esi], 7 ; Since a short is 2 bytes long, each add WORD PTR [esi+2], 7 ; successive element can be accessed add WORD PTR [esi+4], 7 ; by adding 2 more to esi. mov esi, arraylong ; Load ESI with the address of the long array. inc DWORD PTR [esi] ; Since a long is 4 bytes long, each inc DWORD PTR [esi+4] ; successive element can be accessed inc DWORD PTR [esi+8] ; by adding 4 more to esi. retMasmSub ENDP END
Method 1: Step-by-step Instructions for Building CAPP
Method 2Modify a Visual WorkBench makefile and then use it as an external makefile. To do this, use the following steps:
Method 3Use an external makefile to assemble the assembly modules, and use an internal makefile for the main program, which includes the MASM .OBJs built with the external makefile. Simply add the .OBJ files to the project list. With this method, remember to load the external makefile and build the .OBJs after changing any MASM code. By doing this, you can still use the VWB to modify options for the main project, including switching from debug to release. The linker will drop the CodeView information if you select release build for the main project, so always having the debug switches on for the assembler files is not a problem.
Method 4Create an option on the VWB Tools menu to assemble each assembly module as needed. The following setups can be used to create Tools menu items that build the current file:
|
Additional reference words: kbinf 4.00 5.10 5.1 5.10a 5.1a 6.00 6.0 6.00a
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |