Using NASM with Windows and
Visual C++
CS 301 Fall 2001
Prof. Hartman
- Download
NASM and its documentation from the NASM download page.
You want the Windows
Installer and the HTML version of
the documentation. The documentation is also mirrored
locally.
- Run
the installer – put it wherever you like. The default directory is fine –
but remember where it is. You’ll need to know for the next step.
- 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.
- Put
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.
- 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”.
- 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.)
- “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.
Notes:
- 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.
- You
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.