Compiling assembly in Visual Studio Compiling assembly in Visual Studio windows windows

Compiling assembly in Visual Studio


Sounds to me like the custom build rules for .asm files isn't enabled. Right-click the project, Custom Build Rules, tick "Microsoft Macro Assembler". With the "END clear" directive and disabling incremental linking I'm getting a clean build.

It's different starting from VS2010:

  1. Right-click Project, Build customizations, tick "masm".
  2. Right-click the .asm file, Properties, change Item Type to "Microsoft Macro Assembler".


Command line:

Compile the code with:

ml /c /Cx /coff code.asm

You get code.obj as the output.

Link with:

link code.obj /SUBSYSTEM:console /out:go.exe /entry:clear

You can now run go.exe.

Alternatively, do it all in one go with:

ml /Cx /coff code.asm /link /SUBSYSTEM:console /link /entry:clear

Visual Studio (not solved)


Visual Studio includes the MASM macro assembler. Smaller fragments of assembler code are often written in inline assembly in a C or C++ program.

To integrate an assembler file in a Visual Studio project, create a regular C/C++ project (command line or GUI), and just add a file ending in .asm to the list of source files.

To specify clear as the entry point, follow these instructions:

  1. Open the project's Property Pagesdialog box. For details, see SettingVisual C++ Project Properties.

  2. Click the Linker folder.

  3. Click the Advanced property page.

  4. Modify the Entry Point property.

(It was taken from the Visual Studio documentation.)

I can confirm Hans Passant's instruction. In addition, according to this article, if you first add the "build customizations" masm checkbox, and then add the file, it will automatically be recognized as an assembler file. Furthermore, not specifying the entry point name in the END directive, but instead specifying it in the project settings also works for me.