Using MASM (Microsoft Macro Assembler)


This page discusses how to use MASM and is based on Getting Started with MASM and Visual Studio 2026 from Kip Irvine:
  1. Download and Install Microsoft Visual Studio Community.
  2. Visual Studio Community is a fully-featured, extensible, free IDE for creating modern applications for Android, iOS, Windows, as well as web applications and cloud services.



  3. Enable MASM in a C++ Project if Needed.
  4. Using the Microsoft Macro Assembler (MASM) in Visual Studio requires enabling specialized build rules for your project. Because Visual Studio is primarily a C++ IDE, MASM is included within the C++ workload. If you cannot find MASM in Visual Studio Community, it is likely because the workload is missing or the project has not been configured to recognize assembly files. Take the following steps:

    1. Open the Visual Studio Installer.

    2. Select on your Visual Studio Community installation.


    3. Check the box for .

  5. Download and Install the Three Zip Files from GitHub project page:
  6. The page includes the following three zip files:

    • : Code examples and required libraries

    • : Sample 32-bit Visual Studio 2026 project, configured for assembly language

    • : Sample 64-bit Visual Studio 2026 project, configured for assembly language

    Unzip the and put the files in the folder :


  7. Create a Project.



  8. Create a Project.
  9. Copy the project folder from Irvine to a new project folder like :






Arithmetic.asm
COMMENT !
  Calculate an arithmetic mean, (1+2+3+...+n) / n:
  
  1. Read the n.
  2. Calculate the arithmetic series, 1+2+3+...+n.
  3. Divide the sum by n.
  4. Display the quotient, the arithmetic mean.

  Require Irvine32.inc and Irvine32.lib (Kip Irvine's library)
!

INCLUDE Irvine32.inc   ; Include Irvine32 macros and procedures

.data
  prompt1  BYTE "Enter the n: ", 0
  prompt2  BYTE "The arithmetic series: ", 0
  prompt3  BYTE "The arithmetic mean: ", 0
  n        SDWORD ?
  result   SDWORD 0

.code
main PROC
  call  Crlf                  ; New line
  ; Read the n
  mov   edx, OFFSET prompt1
  call  WriteString
  call  ReadInt
  mov   n, eax                ; n   = eax
  mov   ebx, eax              ; ebx = eax

  ; Calculate the aritmetic series
Loop1:    
  cmp   ebx, 0               ; ebx: n
  je    Divide               ; if ( n == 0 )  goto Divide
  mov   eax, result          ; eax = result
  add   eax, ebx             ; eax = result + n
  mov   result, eax          ; result = eax
  mov   eax, ebx             ; eax = n
  sub   eax, 1               ; n = n - 1
  mov   ebx, eax             ; ebx = n
  jmp   Loop1

Divide:
  ; Print the aritmetic series
  mov   edx, OFFSET prompt2
  call  WriteString
  mov   eax, result
  call  WriteInt
  call  Crlf

  ; Calculate the aritmetic mean
  mov   eax, result         ; eax = sum
  mov   ebx, n              ; ebx = n
  xor   edx, edx            ; clear edx
  div   ebx                 ; eax = sum / n
  mov   result, eax         ; result = eax

  ; Print the aritmetic mean
  mov   edx, OFFSET prompt3
  call  WriteString
  mov   eax, result
  call  WriteInt
  call  Crlf            
  call  Crlf

  exit                  ; Exit to operating system
main ENDP
END main
An output example

    Enter the n: 10
    The arithmetic series: +55
    The arithmetic mean: +5

The MASM library from Kip Irvine can be found from here.


To use MASM (Microsoft Macro Assembler) with C++ in Microsoft Visual Studio Community, you need to configure your project to recognize assembly files. MASM tools are included when you install the “Desktop development with C++” workload in the Visual Studio Installer. Enable MASM in Your ProjectVisual Studio does not enable assembly support by default for C++ projects. You must activate the MASM “Build Customization” for each project.
  1. Open your Project: Right-click your project name in the Solution Explorer.
  2. Build Dependencies : Select Build Dependencies > Build Customizations....Select MASM: Check the box next to masm (.targets, .props) and click OK.2. Add an Assembly (.asm) FileOnce customization is enabled, you can add your assembly code.Right-click your project and select Add > New Item....Select C++ File (.cpp), but change the Name extension to .asm (e.g., main.asm).Verification: Right-click the newly added .asm file and select Properties. Under General, the Item Type should automatically be set to Microsoft Macro Assembler. If not, select it manually from the dropdown.3. Assembly vs. C++ IntegrationHow you use MASM depends on your target architecture:x86 (32-bit): You can use inline assembly directly inside your C++ code using the __asm keyword.x64 (64-bit): Inline assembly is not supported. You must write your assembly in a separate .asm file, compile it into an object file, and link it to your C++ project.Entry Point: For standalone assembly projects, you may need to set the entry point (e.g., main) in Project Properties > Linker > Advanced > Entry Point.4. Verification of ToolsIf you cannot find these options, ensure the following are installed via the Visual Studio Community installer:Workload: Desktop development with C++.Individual Components: Verify MSVC v14x - VS 20xx C++ x64/x86 build tools are checked, as they include the ml.exe (32-bit) and ml64.exe (64-bit) assemblers.

  • Check the Web site on a browser by selecting the VWD options:
      Debug  Start Debugging


    Unless there are a Web server and an IP address on your machine, the Web pages can only be accessed by a browser on the local machine. You can see this by noticing the URL is
      https://localhost:60283/WebSite1/Default.aspx
    For grading, you have to submit a CD containing the Website and allow the instructor to execute it on his machine.

  • Execute the Web site and check the result: