If you are using Visual Studio to develop your compiler project you may wish to generate code for Microsoft's MASM assembler and run the compiled code under Visual Studio. These instructions have been used in past years and should be roughly correct, but they have not been tested with 64-bit code under Visual Studio 2010. Please post corrections, hints, and questions on the discussion board, and we will update this page as needed.
To execute the .asm file produced by your compiler, you will need to create a Visual Studio project with a C (not C++) main program and the assembler code from the compiler. The resulting program can be run and debugged using Visual Studio.
The MASM assembler ml.exe
has been included in Visual Studio
for many years and a version that can handle both 32- and 64-bit code should be available in Visual Studio 2010. Code assembled by MASM can be linked and executed
with other
programs,
in
particular
C code.
You may
find
it easiest to use the assembler from a command line or batch script, but it should also be fairly
easy to configure Visual Studio to use MASM
to assemble the .asm
file containing the compiled program. Here
are instructions that have worked in the past.
.asm
file
generated by your compiler to the project. (You may have to change the type
of files
displayed in the dialog to ``all files'' to see the .asm
file.).asm
file.
Select Project>Settings. In the dialog box that appears, be sure that Win32
Debug is displayed in the Settings: field. Expand the file list if needed,
then select your .asm
file -- and only this
file. Click on the Custom Build tab. In the first line of the Build Command(s)
field, enter the MASM command to be used to assemble the file.
ml.exe /c /Cx /coff /Zi ${InputPath}
(The executable file name ml.exe
has a letter l
in it, not a digit 1
. The InputPath macro can be entered by
clicking on button Files and selecting Input Path in the menu that appears.)
Finally, you need to specify the output file name that MASM should use for
the assembled object code. In the Output File(s) field, enter filename.obj
,
where filename is the name of your assembly source file (without
the .asm
suffix).
You should now be able to compile, link, and execute your program with the
normal Visual Studio Build commands. Visual Studio will use MASM to assemble
the .asm
file as needed. You can use the symbolic debugger to step through the assembly
language code, set breakpoints in it, etc.