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.
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'.
We click on that which gives us dialog box as below,
We checkout the tick box for masm (.targets, .props)
On next step, we are gonna add an assembly source code file to compile.
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 ret mainCRTStartup ENDP END
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.
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 ret main ENDP
- codeproject - Assembly Programming with Visual Studio 2010/2012
- SO - How to enable Assembly Language support in Visual Studio 2013
- SO - Compiling Assembly in Visual Studio
- SO - How to enable Assembly Language support in Visual Studio 2015
- ML and ML64 Command-Line Reference
- MASM for x64 (ml64.exe) IDE and Development Tools - Inline Assembler
- msdn - /ENTRY (Entry-Point Symbol)
- SO - Assembly language compilation in Visual Studio 13
- Getting started with ml64.exe
- Getting Started with MASM and Visual Studio 2015
- SO - How can I make a pure assembly project in Visual Studio?
- Guide to Using Assembly in Visual Studio .NET