Using NASM in Visual Studio 6 and 2003.NET

Once you’ve obtained the Win32 archive for NASM, nasmw-inst-xxx.exe (where xxx denotes the version number of NASM contained in the archive), install the NASM into its own directory (for example “C:\Program Files\NASM”).

The archive will contain two executable files: the NASM executable files nasmw.exe, and the NDISASM executable files ndisasm.exe and ndisasmw.exe. In each case, the file whose name ends in w is a Win32 executable, designed to run under Windows 95 or Windows NT Intel.

Since 0.95.36, NASM is fully officially compatible with Microsoft Visual Studio 6/2003.NET.

Integration within Microsoft Visual Studio 6

  • In Tools/Options/Directories , select “Show directories for:” into “Executable files”. Add a new path “C:\Program Files\NASM” (or where you have installed NASM).
  • In your project workspace, create a new folder “Assembler Files”.
  • On this folder, right click and select “Settings”.
  • In General, enable “Always use custom build step”.
  • In Custom Build, change the following settings:

Commands:
nasmw.exe -f win32 -Xvc -o "$(IntDir)$\(InputName).obj" $(InputDir)\$(InputName).asm

Outputs:
"$(IntDir)$\(InputName).obj"

Integration within Microsoft Visual 2003.NET

  • In Tools/Options/Projects, Select “VC++ Directories” and “Show directories for:” “Executable files” – should be the default. Press Ctrl+Insert or press the “New Line” icon. Select the path “C:\Program Files\NASM” (or where you have installed NASM).
  • In your project workspace, create a new folder “Assembler Files”.
  • On this folder, right click and select “Settings”.
  • In General, enable “Always use custom build step”.
  • In Custom Build, change the following settings:

Commands:
nasmw.exe -f win32 -Xvc -o "$(IntDir)\$(InputName).obj" $(InputDir)\$(InputName).asm

Outputs:
"$(IntDir)\$(InputName).obj"

Using Inline Assembler in C/C++ Code

.asm file:

[bits 32]
[section .bss align=16]
[section .data align=16]
[section .text align=16]
[global _myFunction]
_myFunction:
push ebp
mov ebp,esp
mov eax, [ebp + 8] ; your code goes here, instead of this line...
pop ebp
ret
END

in .c/.cpp file call the function:

under MSVS:

int cdecl myFunction(int parameter);

under GCC you’d call the function with ‘_’ prefix:

int _myFunction(int parameter);

For more information see NASM Documentation, chapter 8.

Leave a comment