Using NASM with Windows and Visual C++

CS 301 Fall 2003

Prof. Hartman


Update! See this page for updated Visual C++ 2008 instructions

  1. Download NASM and its documentation from the NASM download page. You'll probably want the Windows binaries and the documentation (although there are also cygwin and linux binaries, which you may use if you wish.) The documentation is also mirrored locally.
  2. Extract the binaries to wherever you like. You should end up with two files, nasmw.exe and ndisasmw.exe.
  3. Put nasmw.exe in your system directory. (C:\WINNT\system32 or C:\WINNT both work under Windows 2000. Similar directories should work under other systems -- the basic idea is that DOS needs to be able to find the file, so it needs to be on your DOS path. If you type "path" in the command window you can see what your path is.)
  4. Make a new "Win32 Console Application" project in Visual C++. The easiest way to do this is to open up Visual C++ and choose "new project". The button for "create new workplace" will be checked, which is probably what you want.
  5. Put the files first.asm,, asm_io.obj, and driver.c into your project directory (Hint -- when saving files, right click, choose "Save Target As", and then change the "Save as type" from "Text Document" to "All Files". This keeps Explorer from adding a .txt extension.) Add first.asm, driver.c, and asm_io.obj to your project. (These file are from the sample code from Carter's book. These are the Microsoft versions, if you are using linux, you'll want to download the linux versions.)
  6. In the file pane of Visual C++, right click on the first.asm file, and choose "settings..." Bring up the "Custom Build" pane. In the "Commands" window type

nasmw.exe -f win32 -l first.lst first.asm

and in the "Outputs" window type "first.obj".

  1. You are now ready to go. To see what is actually going on, you'll need to use the debugger. Choose "Build -> Start Debug -> Step Into (F11)" (and go ahead and build the project if you haven't already.) For the next parts, you'll want the debugger toolbar showing. If it isn't already, you need to right click on the toolbar area and choose "Debug". On the right half of the debugger toolbar are five icons representing little windows. Turn on the "registers" window and the "disassembly" window. (If you hold the mouse pointer over the icon it should show the name of the window it will bring up.)
  2. "Step over" (F10, or use the icons in the middle of the debugger toolbar) code lines until you are at the line beginning "call _asm_main(#######)" Now "Step Into" (F11). You should see the beginning of the code you assembled. You can step through it and watch the registers.