Chat Box

Monday, February 2, 2009

How to run Assembly Programs in Visual Studio

First, you must install some version of Visual Studio or Visual C++ Express:
  1. If you have installed Visual Studio 2008 Professional or Team Suite, these products also contain the Microsoft Assembler 9.0.
  2. If you have installed Visual C++ 2008 Express Service Pack 1, it includes the Visual C++ 2008 Feature Pack, which also includes MASM 9.0.
  3. If you have installed Visual C++ 2005 Express, you must also download the Microsoft Assembler 8.0
    (see below).
Downloading Microsoft Express Editions

When you run the setup program for either of these, make a note of the location where the C++ compiler is installed. This information will be useful to you later.

Downloading and installing the Microsoft Assembler 8.0: Visit Microsoft's MASM 8.0 download site. Follow the download and installation instructions on the Microsoft page. If the link is broken, please let us know by email. Note that this MASM download only works with Visual C++ 2005 Express. MASM 8.0 is almost identical to MASM 9.0.

Next: Install the Example Programs

The latest copy of the example programs are listed below.

Example programs and link libraries (designed for Visual Studio 2008) New
Example programs and link libraries (designed for Visual Studio 2005)

The examples are stored in a self-extracting archive file that automatically extracts to the c:\Irvine folder. Unless you have some objection to using that location, do not alter the path. (Lab managers: you can designate c:\Irvine directory as read-only.) If you plan to change the installation location, read our instructions relating to changing project properties.

The folllowing files will be copied into the c:\Irvine directory:



Include file for writing Windows applications

Include file used with the Irvine16 link library (16-bit applications)


16-bit link function library used with this book

Include file used with the Irvine32 link library (32-bit applications)

Link16.exe 16-bit linker


32-bit link function library used with this book

Include file containing macros (explained in Chapter 10)

Small-sized include file, used by

make16.bat Batch file for building 16-bit applications

Keyboard code definitions file, used by

A subdirectory named Examples will contain all the example programs shown in the book.

Building a Sample Assembly Language Program

Preliminary Step: Set Tab Size to 5

Start Visual C++ Express, and select Options from the Tools menu. Select Text Editor, Select All Languages, and select Tabs:

Set the Tab Size and Indent Size to 5.

Opening a Project

Visual Studio and Visual C++ Express require assembly language source files to belong to a project, which is a kind of container. A project holds configuration information such as the locations of the assembler, linker, and required libraries. A project has its own folder, and it holds the names and locations of all files belonging to it. We have created a sample project folder in the c:\Irvine\Examples directory, and its name is Project_Sample.

Do the following steps, in order:

  1. Start Visual Studio or Visual C++ Express.
  2. If you're using Visual Studio, select Open Project from the File menu. Or, if you're using Visual C++ Express, select Open, and select Project/Solution.
  3. Navigate to the c:\Irvine\Examples\Project_Sample folder and open the file named Project.sln.
  4. In the Solution Explorer window, click the + symbol next to the item named Project to expand it. Double-click the file named main.asm to open it in the editing window. (Visual Studio users may see a popup dialog asking for the encoding method used in the asm file. just click the OK button to continue.)

Tip: If the Solution Explorer window is not visible, select Solution Explorer from the View menu. Also, if you do not see main.asm in the Solution Explorer window, look at the tabs along the bottom of the window. Click the Solution Explorer tab.

You should see the following program in the editor window:

TITLE MASM Template (main.asm)

; Description:
; Revision date:


myMessage BYTE "MASM program example",0dh,0ah,0

main PROC
call Clrscr

mov edx,OFFSET myMessage
call WriteString

main ENDP

END main

Later, we'll show you how to copy this program and use it as a starting point to write your own programs.

Build the Program

Next, you will build (assemble and link) the sample program:

  • If you're using Visual C++ Express, select Build Solution from the Build menu.
  • If you're using Visual Studio, select Build Project from the Build menu.

In the output window at the bottom of the screen, you should see messages similar to the following, indicating the build progress:

1>------ Build started: Project: Project, Configuration: Debug Win32 ------
1>Assembling: .\main.asm
1>Embedding manifest...
1>Build log was saved at "file://g:\masm\Project_sample\Debug\BuildLog.htm"
1>Project - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

If you do not see these messages, the project has probably not been modified since it was last built. No problem--just add a space somewhere in the document, save it, and try the Build command again.

Run the Program

Select Start without Debugging from the Debug menu. The following console window should appear, although your window will be larger than the one shown here:

The "Press any key to continue..." message is automatically generated by Visual C++ Express.

Congratulations, you have just run your first Assembly Language program.

Press any key to close the Console window.

When you assembled and linked the project, a file named Project.exe was created inside the project's \Debug folder. This is the file that executes when you run the project. You can execute Project.exe by double-clicking its name inside Windows Explorer, but it will just flash on the screen and disappear. That is because Windows Explorer does not pause the display before closing the command window.

Creating New Projects of Your Own

Before long, you will want to create your own projects. The easiest way to do this is to copy the entire c:\Irvine\Examples\Project_Sample folder to a new location. Copy it to a folder in which you have read/write permissions. (If you're working in a college computer lab, a useful location is a portable USB drive. Then you can modify the program, build, and run it again.

Step 5: Running the Sample Program in Debug Mode

In this step, you will set a breakpoint inside the sample program. Then you will use the Visual C++ debugger to step through the program's execution one statement at a time.

  1. To begin stepping through your program in Debug mode, press the F10 key.
  2. A yellow arrow will appear next to the first program statement (call Clrscr).The arrow indicates that the statement is next to be executed.
  3. Press the F10 key (called Step Over) to execute the current statement. Continue pressing F10 until the program is about to execute the exit statement.
  4. A small black window icon should appear on your Windows status bar. Open it and look at the contents of the Command window. You should see the words "MASM program example" in the window.
  5. Press F10 one more time to end the program.


If you want to display the CPU registers, do the following: Start debugging the program, then select Windows from the Debug menu. Select Registers from the drop-down list. The bottom window will display the register contents. Right click this window and check the item Flags to enable the display of conditional flags.

You can interrupt a debugging session at any time by selecting Stop Debugging from the Debug menu. You can do the same by clicking the blue square button on the toolbar. To remove a breakpoint from the program, click on the red dot so that it disappears.

Setting a BreakPoint

If you set a breakpoint in a program, you can use the debugger to execute the program a full speed (more or less) until it reaches the breakpoint. At that point, the debugger drops into single-step mode.

  1. Click the mouse along the border to the left of the call WriteString statement. A large red dot should appear in the margin.
  2. Select Start Debugging from the Debug menu. The program should run, and pause on the line with the breakpoint, showing the same Yellow arrow as before.
  3. Press F10 until the program finishes.

You can remove a breakpoint by clicking its red dot with the mouse. Take a few minutes to experiment with the Debug menu commands. Set more breakpoints and run the program again. For the time being, you can use the F11 key to step through the program in the same way the F10 key did.

Building and Running Other Programs

Suppose you want to run another example program, or possibly create your own program. You can either edit and modify main.asm, or you can remove main.asm from the project and insert some other .asm file into the project.

  • To remove a program from a project without deleting the file, right-click its name in the Solution Explorer window. In the context menu, select Exclude from Project. If you change your mind and decide to add it back to the project, right-click in the same window, select Add, select Existing item, and select the file you want to add.
  • To remove a program from a project and delete the source code file, select the file with the mouse and press the Del key. Or, you can right-click the file name and select Remove.

Adding a File to a Project

The easiest way to add an assembly language source file to an open project is to drag its filename with the mouse from a Windows Explorer window onto the name of your project in the Solution Explorer window. A reference to the file (not a copy) will be inserted in your project's directory. Try this now:

  1. Remove the main.asm file from your project.
  2. Add a reference to the file c:\Irvine\Examples\ch03\AddSub.asm to the project.
  3. Build and run the project.

Here is what you should see in the Console window, except that only your EAX register will have the same value as ours:

When you press a key, the console window will close.

Copying a source file

If you want to make a copy of an existing file, use Windows Explorer to copy the file into your project directory. Then, right-click the project name in Solution Explorer, select Add, select Existing Item, and select the filename.


Anonymous said...

thats so nice ...

but i have a problem, i can't download the example programs, the link is broken ... please i really need to have them !!!

my mail :

thanks guys

Anonymous said...

I'm also facing the same problem: 'Page cannot displayed' when I click on the link 'Example Progms and Link Libraries'.

Can anybody provie me the example.

Email Id:

Anonymous said...

Hi Guys,

I found the links here:

Anonymous said...

Info nicely applied!.
My site: seks dziewczyny, seks dziewczyny: http:
my site - seks dziewczyny

Anonymous said...

Have you ever considered about adding a little bit more than
just your articles? I mean, what you say is fundamental and all.
But think about if you added some great visuals or videos to give your posts more, "pop"!
Your content is excellent but with images and videos, this site could
undeniably be one of the greatest in its niche. Terrific blog!

Anonymous said...

This website was... how do I say it? Relevant!! Finally I
have found something that helped me. Appreciate it!

See this: zobacz, http:

Anonymous said...

This site was... how do you say it? Relevant!
! Finally I have found something which helped me. Thanks!
zobacz szczegóły, http:

Anonymous said...

This is a topic which is near to my heart... Cheers! Where are your contact details though?
więcej, http://www.ęcia/

Anonymous said...

I have to thank you for the efforts you have put in penning this website.
I'm hoping to check out the same high-grade blog posts by you later on as well. In truth, your creative writing abilities has inspired me to get my own, personal blog now ;)
See this: zobacz,

Anonymous said...

Right away I am going away to do my breakfast,
later than having my breakfast coming yet again to
read more news.

Feel free to visit my web blog :: Go Here

Anonymous said...

Wonderful goods from you, man. I have understand your stuff
previous to and you are just extremely wonderful. I actually like what you have acquired here,
certainly like what you are stating and the way in which you say it.
You make it enjoyable and you still care for to keep it smart.
I can't wait to read much more from you. This is actually a tremendous web site.

My weblog ... Iyapaway.Com

Anonymous said...

Thanks for sharing your thoughts about fleece fabric. Regards

Take a look at my website:

Anonymous said...

Its like you read my mind! You seem to grasp a lot about this, like you
wrote the book in it or something. I feel that you just can
do with some % to drive the message house a bit, but other than that, that is excellent blog. An excellent read. I will definitely be back.

My web-site:

Anonymous said...

Howdy! This article couldn't be written much better! Reading through this post reminds me of my previous roommate! He constantly kept preaching about this. I most certainly will forward this article to him. Pretty sure he will have a very good read. I appreciate you for sharing!

my web site - exercises to jump higher exercises to improve vertical exercises to improve vertical jump exercises to improve vertical leap exercises to increase vertical exercises to increase vertical jump exercises to increase vertical leap exercises for vertical exercises for vertical jump exercises for vertical leap workouts to jump higher workouts to improve vertical workouts to improve vertical jump workouts to improve vertical leap workouts to increase vertical workouts to increase vertical jump workouts to increase vertical leap workouts for vertical workouts for vertical jump workouts for vertical leap vertical jump exercises vertical leap exercises vertical jump workouts vertical leap workouts

Anonymous said...

I'm truly enjoying the design and layout of your site. It's a very easy on
the eyes which makes it much more pleasant for me to come here and
visit more often. Did you hire out a designer to create your theme?
Excellent work!

My weblog :: student loan consolidated

Anonymous said...

Good site you have got here.. It's difficult to find excellent writing like yours nowadays. I really appreciate people like you! Take care!!

Stop by my blog: workouts to increase vertical jump

Anonymous said...

Howdy I am so thrilled I found your blog, I
really found you by error, while I was looking on Askjeeve for something else,
Anyhow I am here now and would just like to say
thank you for a fantastic post and a all round enjoyable blog
(I also love the theme/design), I don't have time to browse it all at the minute but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the awesome work.

Here is my blog post ...

Anonymous said...

Hello to all, how is everything, I think every one is
getting more from this web page, and your views are fastidious in favor of new people.

Feel free to surf to my web blog :: workouts to improve vertical

Anonymous said...

My programmer is trying to convince me to move to .
net from PHP. I have always disliked the idea because of the expenses.
But he's tryiong none the less. I've been
using WordPress on a number of websites for about a year and am nervous about switching to another platform.
I have heard very good things about Is there a
way I can transfer all my wordpress posts into it? Any help would be
really appreciated!

Also visit my weblog :: Http://Waltoncountywiki.Com/TorstenrkWoodruffxd

Anonymous said...

I'm impressed, I must say. Rarely do I encounter a blog that's both
equally educative and amusing, and without a doubt, you have hit the nail on
the head. The issue is an issue that too few folks are speaking
intelligently about. I am very happy that I found this in my search
for something regarding this.

Feel free to visit my weblog

Anonymous said...

I know this web site offers quality based posts and additional data,
is there any other site which provides these things in quality?

Here is my web page - workouts to increase vertical leap

Anonymous said...

It's an remarkable piece of writing in favor of all the web viewers; they will obtain benefit from it I am sure.

Here is my weblog;

Anonymous said...

I tend not to drop many comments, but i did a few searching and wound up here "How to run Assembly Programs in Visual Studio".
And I do have 2 questions for you if you don't mind. Is it simply me or does it give the impression like a few of these remarks look like they are written by brain dead people? :-P And, if you are posting at additional online sites, I'd like to follow everything new you have to post.
Would you make a list of all of all your social pages like your Facebook page, twitter feed,
or linkedin profile?

Here is my web site -

Anonymous said...

Hi, this weekend is nice in support of me, because this occasion i am reading this enormous informative piece of writing here at my residence.

Feel free to surf to my blog -

Anonymous said...

Hi there everyone, it's my first pay a visit at this site, and post is really fruitful in support of me, keep up posting these articles.

my page ... workouts to improve vertical leap

Anonymous said...

Wѕzyscy ludzie, κtórych poznałeś – dosłоwnie wszyscy
– nie pojawili ѕię tu pгzyρaԁκowo.

Ρrzyszli, by Cię czegoś nauczyć. Z specyfikacϳi wybieramy sobie
ludzi, jakich mamу spotkać przed naгoԁzinami.

Jednakowoż dzisiaj zagłębie się w jeden, speсyficzny rodzaj poznania, mianowicie: Βlіѕkości Inκarnaсуjnej.

Рodeјrzewam, iż każdy ma w otoczenіu osobę,
którą znalіśmy w poρrzednіch wcieleniach… Kiedy to odczuć?

My homeрage: Totalagencja.Angelfire.Com

Anonymous said...

naturally like your web-site however you need to check the spelling on quite a
few of your posts. Many of them are rife with spelling problems
and I to find it very troublesome to tell the reality on the other hand I will surely come back again.

my blog: exercises to increase vertical jump

Anonymous said...

Hi, Neat post. There's an issue with your web site in web explorer, would test this? IE still is the marketplace leader and a big part of folks will miss your excellent writing because of this problem.

My website - workouts to improve vertical jump

Anonymous said...

You've made some decent points there. I checked on the net to find out more about the issue and found most people will go along with your views on this site.

Here is my site ::

Post a Comment