Compiling Assembly Programs using Visual Studio 2015

Tags: assembly lang, visual studio


To compile assembly programs using Visual Studio we need to change project build configuration and use recongnized entry point for the program which is not main. On the next section, we describe how we do it with screenshots.


We need to create a new project using Visual Studio. Project type is C/C++ Console.

Step 1

We change the build configuration to support masm targets as we are gonna work on assembly code. To do that, we right click the project from 'Solution Explorer' and click 'Build Dependencies' which gives us 'Build Customizations'.

Visual Studio - Build Configuration to enable Assembly Compilation

We click on that which gives us dialog box as below,

Build configuration dialog box

We checkout the tick box for masm (.targets, .props)

On next step, we are gonna add an assembly source code file to compile.

Step 2

Here is our example assembly program. We name the file as 'Main.asm',

.586              ;Target processor.  Use instructions for Pentium class machines
.MODEL FLAT, C    ;Use the flat memory model. Use C calling conventions
.STACK            ;Define a stack segment of 1KB (Not required for this example)
.DATA             ;Create a near data segment.  Local variables are declared after
                  ;this directive (Not required for this example)
.CODE             ;Indicates the start of a code segment.

mainCRTStartup PROC
   xor eax, eax
   xor ebx, ebx
mainCRTStartup ENDP 

Now build the project and run. This program is pretty simple and won't show any output. However, this is good for demonstration purpose. We have taken the code example from reference 3.

If you put a wrong name for the procedure it will give you this error during build,

LINK32 : error LNK2001: unresolved external symbol _mainCRTStartup
test.exe : fatal error LNK1120: 1 unresolved externals

On step 2, we describe how we can change the entry point of the program to something else if we want. By default it is mainCRTStartup for C/C++ Console project.

There is a way to specify the entry point name in the configuration so it is passed to the linker. Changing Entry Point Name in Visual Studio Project Configuration

For example, we type in 'main' there so entry point is named main. Afterwards, we change the routine of our previous program to this,

main PROC
   xor eax, eax
   xor ebx, ebx
main ENDP 


  1. codeproject - Assembly Programming with Visual Studio 2010/2012
  2. SO - How to enable Assembly Language support in Visual Studio 2013
  3. SO - Compiling Assembly in Visual Studio
  4. SO - How to enable Assembly Language support in Visual Studio 2015
  5. ML and ML64 Command-Line Reference
  6. MASM for x64 (ml64.exe) IDE and Development Tools - Inline Assembler
  7. msdn - /ENTRY (Entry-Point Symbol)
  8. SO - Assembly language compilation in Visual Studio 13
  9. Getting started with ml64.exe
  10. Getting Started with MASM and Visual Studio 2015
  11. SO - How can I make a pure assembly project in Visual Studio?
  12. Guide to Using Assembly in Visual Studio .NET

No Comments

Add a Comment