Top > Programming > Assembly in VC++
This is my guide to using Microsoft Visual C++ to efficiently program assembly (of the MASM
variety, but these instructions can be adapted for other varieties).
- Before you do anything else, have you installed the
latest
service
pack?
- You'll need to start by getting the
Processor Pack
for Visual C++. This will install, among other things, the Microsoft Macro Assembler (MASM).
You need this to do assembly-type stuff....
- Make sure your %INCLUDE%, %LIB%, and %PATH% variables are set up correctly.
(You decide what that means. Are all the standard headers you want included found? Are all the libraries
you want to link to detected? Do all the commands you type in execute?)
- Alright, fire up VC++. First we're going to set up the "tools" we're going to use.
- Go to Tools / Customize...
- Click on the Tools tab
- Set up the Assemble tool
- Enter ml.exe into the Command: section
- Enter -Zi -c -Fl -coff $(FileName)$(FileExt) into the Arguments: section.
$(FileName) and $(FileExt) are variables handily created by Visual C++.
Note that if you pass different arguments into the assembler, here's where you put them in.
- Enter $(FileDir) into the Initial Directory: section.
- Lastly, enable the Use Output Window checkbox. This redirects the output from the
assembler into the output window of VC++, under the "Assemble" tab (or whatever you named the
tool).
- Set up the Link tool
- Enter link.exe into the Command: section
- Enter $(FileName).obj irvine32.lib kernel32.lib /SUBSYSTEM:CONSOLE /DEBUG /MAP
into the Arguments: section. Note that if you use different libraries by default,
here's where to put them. irvine32.lib is the library that comes with
Assembly Language for Intel-Based Computers
by Kip R. Irvine.
- Enter $(FileDir) into the Initial Directory: section.
- Again, enable the Use Output Window checkbox. This time output will be put under
the "Link" tab.
- Finally, set up the Run tool
- Enter cmd.exe into the Command: section
- Enter /c $(FileName).exe into the Arguments: section. Note that if you
want to call your program with any command line arguments, you'll need to pull up a command
prompt and do it by hand.
- Enter $(FileDir) into the Initial Directory: section.
- You'd think that Prompt for arguments would be helpful, but I haven't figured it
out yet. Play around with it.
- So now we've got the tools set up. Now all we need to do is put them on the toolbar.
- Note which tools they are. For me they were tools 8, 9, and 10 for Assemble, Link, and Run,
respectively.
- Switch to the Commands section of the Customize dialog box
- Select the Tools category from the drop-down list
- Drag the Assemble tool (so tool 8 for me) onto some empty space on the toolbar. This will
create a new toolbar.
- Drag the Link and Run tools (tools 9 and 10) onto the newly-created toolbar. You should
now have a toolbar with three similar icons on it.
- By default, the new toolbar is called something like "Toolbar1". This is lame. Switch
over to the Toolbars tab and find the toolbar you created. Rename it something
appropriate, like "Assembly".
- Program efficiently in assembly!
If you're using something else, say NASM, then hopefully you know enough to change what you need
to change to get it to work, because I don't know anything about NASM. You'll probably be
skipping step 1, and changing steps 3.3.1 and 3.3.2.
Also, if you're using a different version of Visual Studio (that is, not version 6), then
I hope you didn't need everything spelled out to you in quite so explicit detail, because it's
probably going to be slightly different for you.
This was spelled out in agonizing detail, with a great many "duh" steps, because I have a
tendency to forget how to set something like this up again should I, oh, say, reformat. Usually
by the time I get past the hardware setup and operating system install phases and into the
application install phase, it's 3 or 4 in the morning and I'm very tired. This way I don't miss
anything.
-Jason