| Getting Started with MASM and Visual Studio 2026 | |||||||||||||||||||||||||||
|
Updated 3/15/2026
This tutorial assumes that you are using either the 7th or 8th Edition of Assembly Language
for x86 Processors, and you are using Visual Studio 2026.
Before starting the tutorials listed below, please
visit our GitHub project page (surferkip/asmbook) to download the following files:
Required Setup for 32-bit ApplicationsWhen you install the VS 2026 Community Edition, be sure to include the Visual C++ Desktop development option in your selections. First, let's see if it has already been installed (as often happens in college computer labs). When you start Visual Studio, click the "Create a new project" panel on the startup window:
Next, in the Create a new project dialog window, select C++ from the dropdown list that is currently labeled All languages. Now the dialog window will appear like this:
If you do not see C++ in the list, close Visual Studio and run a separate program named the Visual Studio Installer. If your computer is in a college laboratory, your account may not have sufficient privileges to run this program, so you can ask your lab supervisor to do it for you.
Tip: Just for fun, you might want to continue creating the project, and when you see a C++ program in your main edit window, select Build Solution from the Build menu. Press the F5 function key to run the program, and a windows console dialog window should appear, saying "Hello World!".
The C++ language package in Visual Studio always includes the Microsoft Assembler (MASM) tool, filename ml.exe. You can find it at
C:\Program Files\Microsoft Visual Studio\2026\Community\VC\Tools\MSVC\14.nn.nnnn\bin\HostX64\x86, where the n characters above indicate digits in the version number of your current VS installation.) The Book's Example ProgramsAt the top of this document, we explained how to download the file named Irvine.zip and extract it into the C:\Irvine folder. Unless you have some objection to using that location, do not alter the path. (Note to lab administrators: you can designate c:\Irvine directory as read-only.).The folllowing files should appear in the c:\Irvine directory:
A subdirectory named Examples will contain all the example programs shown in the book, source code for the book's 16-, 32-, and 64-bit libraries, and a couple of sample projects for earlier versions of Visual Studio. Configuring Visual Studio
You can open Visual Studio without opening or creating a project. In the Get started dialog window, select Continue without code in the lower right corner.
Select the C++ ConfigurationVisual Studio supports multiple programming languages and application types. The C++ programming language configuration most closely matches that of assembly language programming, so we suggest the following steps:
Optional Step: Set the tab indent sizeStart Visual Studio and select Options from the Tools menu. Select and expand the Languages item (near the top of the list), select Defaults, and in the middle panel, scroll down to Tabs. From here, you can set the tab and indent sizes. Optionally, you may want to select the Insert spaces option. The following values are fairly standard for assembly language programming:
Tutorial: Building and running a 32-bit programLet's open and build our first 32-bit project.Opening a ProjectVisual Studio requires assembly language source files to belong to a project, which is a kind of container. A project holds configuration information such as the locations of the assembler, linker, and required libraries. A project has its own folder, and it holds the names and locations of all files belonging to it. Following the instructions at the top of this web page, download the Project32_VS2026.zip file and unzip it into your working directory. It contains a sample asm test file named AddTwo.asm.Follow these steps:
You should see the following program in the editor window:
Adding a File to a Project: Whenever you want to add an .asm file to an open project, do the following: (1) Right-click the
project name in the Visual Studio window, select Add, then select Existing Item... (2) In the Add Existing Item
dialog window, browse to the location of the file you want to add, select the filename, and click
the Add button to close the dialog window.
Build the ProgramNow you will build (assemble and link) the sample program. Select Build Project from the Build menu. In the Output window for Visual Studio at the bottom of the screen, you should see messages similar to the following, indicating the build result:
(The shaded area in this image represents a machine-specific path.)
If you do not see these messages, the project has probably not been modified since it was last built. No problem--just select Rebuild Project from the Build menu. Run the Program in Debug ModeThe easiest way to run your first program is to use the debugger. First, you must set a breakpoint. When you set a breakpoint in a program, you can use the debugger to execute the program a full speed (more or less) until it reaches the breakpoint. At that point, the debugger drops into single-step mode. Here's how to do it:
Don't be surprised to see a new window instantly appear named the "Console window", with a plain black background. It's the window that displays your program's output while you're stepping through the code.
You can remove a breakpoint by clicking its dot with the mouse. Take a few minutes to experiment with the Debug menu commands. Set more breakpoints and run the program again. Here's what your program will look like when paused at the breakpoint:
Running a program from the Command PromptWhen you assembled and linked the sample project, a file named Project.exe was created inside the project's \Debug folder. This file executes when you run the project. You can execute any exe file by double-clicking its name inside Windows Explorer, but it will often just flash on the screen and disappear. That is because Windows Explorer does not pause the display before closing the command window. On the other hand, you can open a Command prompt window, move to the Debug directory, and run Project.exe by typing "Project" (without the quotes). You might want to do some online reading about Windows shell commands if you plan to use the command line.
Final note: To remove a source file from the Visual Studio window, right-click its filename and select Remove. The file will not be deleted from the file system. On the other hand, if you want to delete the file, select it and press the Del key.
RegistersSoon you will want to display CPU registers when debugging your programs. Here's how to make them visible: First, under the Tools >> Options menu, select Debbuging in the left panel, and select Enable address-level debugging. Next, set a breakpoint in your source code on an executable statement, run your program in Debug mode, select Windows from the Debug menu, and then select Registers from the drop-down list. The Registers window may appear docked to the Visual Studio workspace, but you may find it helpful to let the window float so you can move it anywhere on your computer desktop. You can grab the window header with the mouse and pull it to a new location. You will also want to display the CPU flags inside the Registers window. To do that, right click inside the Registers window and check the word Flags from the popup menu. Here's what it looks like:
Building and Running Other ProgramsSuppose you want to run another example program, or possibly create your own program. You can remove the existing assembly language file from the Solution Explorer window and insert a new .asm file into the project.
Adding a File to a ProjectAn easy way to add an assembly language source file to an open project is to drag its filename with the mouse from a Windows Explorer window onto the name of your project in the Solution Explorer window. The physical file will not be copied--the project only holds a reference to the file's location. Try this now:
Copying a Source FileOne way to make a copy of an existing source code file is to use Windows Explorer to copy the file into your project directory. Then, right-click the project name in Solution Explorer, select Add, select Existing Item, and select the filename. Tutorial: Building and running a 64-bit programIn this tutorial, we will show you how to assemble, link, and run a sample 64-bit program. We assume you have already completed our tutorial entitled Building a 32-Bit Assembly Language Program.Do the following steps, in order:
You should see the following program in the editor window: ; AddTwoSum_64.asm - Chapter 3 example. ExitProcess proto .data sum qword 0 .code main proc mov rax,5 add rax,6 mov sum,rax mov ecx,0 call ExitProcess main endp end(Notice that the program's entry point is the main procedure. If you wish to use a different name for your startup procedure in your own programs, you can modify this option by selecting Properties from the Project menu, and then selecting Linker / Advanced / Entry Point.) Build the ProgramSelect Build Project from the Build menu. You should see text written to Visual Studio's output window like the following:1>------ Build started: Project: Project, Configuration: Debug x64 ------ 1> Assembling AddTwoSum_64.asm... 1> Project64.vcxproj -> ...\Project64_VS2022\x64\Debug\Project.exe ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========If you do not see these messages, the project has probably not been modified since it was last built. No problem--just select Rebuild Project from the Build menu. You use the same Visual Studio commands to run and debug 64-bit programs as you would for 32-bit programs. Notice that the Registers window displays all the 64-bit registers:
Building 16-bit programs (Chapters 14-17)Only Chapters 14 through 17 require you to build 16-bit applications. Except for a few exceptions, which are noted in the book, your 16-bit applications will run under the 32-bit versions of Windows (Windows XP, Windows Vista, Windows 7).
If you're interested in running 16-bit programs under 64-bit Windows, you
will need to enable a feature named NTVDM.)
Click here to read a web site with instructions on how to do this. Another
alternative you may wish to explore is to install a virtual machine (using a free program named VirtualBox from Oracle) and install 32-bit Windows on the virtual machine.
The book's example programs in Chapters 1-13 have been successfully
tested in 32-bit Windows 7,8, and 10. On the other hand, many programs in Chapters 14-17 will not run in any Microsoft OS later than Windows 98, because they rely on direct access to hardware and system memory.
You cannot directly run 16-bit applications in any 64-bit version of Windows.
If you plan to build 16-bit applications, you need to add two new commands to the Visual Studio Tools menu. To add a command, select External Tools from the Tools menu. The following dialog will appear, although many of the items in your list on the left side will be missing. Download the batch file here (rename the .txt extension to .bat after downloading): make16_vs2026.txt.
Step 1: Create the Build 16-bit ASM CommandClick the Add button and fill in the Title, Command, Arguments, and Initial directory fields as shown in the screen snapshot. If you click the buttons with arrows on the right side of the Arguments and Initial directory fields, a convenient list appears. You can select an item without having to worry about spelling:
Click the Apply button to save the command.
Step 2: Create the Run 16-bit ASM CommandClick the Add button again, and create a new command named Run 16-bit ASM:
Uncheck the "Close on exit" option and click the OK button to save the command and close the External Tools dialog. Testing Your new 16-Bit CommandsTo test your new 16-bit commands, close any Visual Studio project that happens to be open. Then, select File | Open | File from the menu and choose the file named 16-bit.asm from the ch03 folder in the book's example programs. Select Build 16-bit ASM from the Tools menu. The following command window should appear, showing the successful execution of the assembler and linker, followed by a listing of all files related to this program:
Press a key to close the window. Next, you will run the program. Select Run 16-bit ASM from the Tools menu. The following window will appear, although the contents of all registers except EAX will be different:
Press a key to close the window. You have completed the setup for building and running 16-bit assembly language programs. Upgrading Existing Visual Studio Projects to VS 2026Visual Studio 2026 makes it easy to convert an existing project to the current version. We suggest you first make a backup copy of your existing projects. Next, in the Visual Studio IDE, select Open from the File menu, then select Project/Solution. The Setup assistant dialog will then notify you that your Platform Toolset is outdated:
Select the Retarget all button and then click the Apply button. And just like that, your project will be ready to go in VS 2026. Note: once you convert a project to VS 2026, you cannot revert it to the original version!
Was your program's EXE file blocked by an Antivirus scanner?Antivirus scanner software has improved greatly in recent years, and so have the number of viruses (one website reports 50,000 at present). Because of this, your computer's antivirus scanner may report a false positive when you build your program, and refuse to let you run it. There are a few workarounds: (1) You can add your project's bin/debug folder into an exclusion list in your antivirus configuration. This is my preferred approach, and it nearly always works. (2) You can suspend your realtime antivirus scanner software, but this will leave you open to malware for a short time. If you choose this option, be sure to temporarily disconnect your computer from the Internet. Return to top
|