Using NASM with Windows and
CS 301 Fall 2003
Update! See this page for
updated Visual C++ 2008 instructions
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.
the binaries to wherever you like. You should end up with two files, nasmw.exe and ndisasmw.exe.
- 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.)
- 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.
the files first.asm,
asm_io.inc, 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.)
- 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
nasmw.exe -f win32 -l first.lst first.asm
and in the "Outputs" window type "first.obj".
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.)
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.
- The "-f win32" command line option to
nasmw.exe tells NASM to create a WIN32 .obj
file from the .asm file.
- The "-l first.lst" command line option
to nasmw.exe tells NASM to create a "listing" file as it is assembling.
Take a look at the file first.lst.
can turn on the disassembly window for any program you are debugging. It
might be fun to look at a short C program as compiled by Visual C++ to see
what the disassembled code looks like.