updated 01/11/2024
Occasionally I use Intel assembler language to squeeze processing power from my programs.
A cheap solution was C inline assembler sections, but VS2022 doesn’t support them in a 64-bits program. Other compilers use more or less complex solutions (IBM assembler, …).
This forced me to consider including and linking .asm files in my projects. I can split them with 32 and 64 bits code and compile them when needed. Then I tried to use MASM included in Visual Studio… but I found it really complex to use, and quite poorly documented.
So I started to consider using NASM, an open-source assembler compiler, simpler and much better documented.
Download and Installation
The first step is to download and install the following needed pieces.
- NASM ‘compiler’ from its Home Site.
- VSNASM is an open-source project to integrate it into Visual Studio from GitHub.
then install the first file (for example into “c:\nasm” folder) and copy VSNASM files in the same folder.
The last thing is to define 2 different environmental variables with the installation folder:
- NASMPATH with the final ‘\‘ (“c:\nasm\” in our example).
- NASMPATH_VS without the final ‘\‘ (“c:\nasm” in our example).
NOTE1: I warmly suggest installing it, in the ‘program files‘ folder to keep them safer.
NOTE2: I also warmly suggest editing ‘nasm.xml‘ to change the DisplayName to “NASM – Netwide Assembler” into the nodes listed below at the end of the file:
- ItemType
- ContentType
Setting up Visual Studio
Start Visual Studio and:
- open ‘Tools‘->’Options…‘ window from the main menu.
- go to ‘Projects and Solutions‘ -> ‘VC++ Project Settings‘.
- add ‘$(NASMPATH_VS)‘ to ‘Build Customization Search Path‘.
- confirm and exit.
Once installed, it can be configured for Nasm Intel Syntax highlighting from VS options.
If using VS2022, even if it is not mandatory, I suggest also installing ‘AsmDude‘ extension for syntax highlighting into .asm files.
VS Project Setup
The last step is to enable .asm support in your project.
- open your project.
- right-click each project using .asm files.
- select ‘Build Dependencies‘->’Build Customizations‘.
- check ‘nasm‘ option.
- confirm.
Then for each .asm file, you have to:
- open the file ‘Properties‘
- set into ‘General‘->’Item Type‘ to ‘Netwide Assembler‘ (or whatever you set, “NASM – Netwide Assembler” in my case).
- enable the debug information for the debug profile from the specific NASM options.
- confirm.
NOTE: from this last property window, we can also set whether to compile the file or not in 32/64 bits target platforms.
Conclusions
After all these steps, we can start with something like:
bits 32 section .data <put your data here> section .text <put your function here>
Have fun