Getting Started | ||||||||||||||||||||||||||
Updated 8/12/2006 Let's assume that you bought Assembly Language for Intel-Based Computers 5/e and you need to get all the necessary software and sample programs installed so you can start working. Except where noted, all instructions in this document apply equally to Visual Studio 2005 and Visual C++ 2005 Express. Contents
Required Setup for 32-bit ApplicationsIf you are using Visual Studio 2005 Professional or Team Suite, these products already contain the Microsoft Assembler 8.0. You can skip Steps 1 and 2 and go directly to Step 3. Step 1: Install Visual C++ 2005 Express EditionYou may have received a CDROM accompanying this book depending on which edition your bookstore ordered. The CDROM contains Visual C++ 2005 Express Edition. You will use it to write, edit, compile, debug, and run your assembly language programs. If you did not receive a CDROM, download the software now from Microsoft. (If the preceding link has changed, go to http://msdn.microsoft.com/vstudio and search for the Express editions.) When you run the Visual C++ setup program, make a note of the location where the C++ compiler is installed. This information will be useful to you later. From now on, we will leave the "2005" out of the name Visual C++ Express. Step 2: Download and Install the Microsoft AssemblerVisit 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. Step 3: Installing the Book's Example ProgramsClick this link to get the latest copy of the book's link libraries and example programs. 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 do 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:
You have now installed the book's link library and example programs. Step 4: Building a Sample Assembly Language ProgramPreliminary Step: Set Tab Size to 5Start 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 ProjectVisual Studio and Visual C++ Express requires assembly language source files to belong to a Project, which is a kind of container. A project holdsconfiguration information, such as the location of the assembler, linker, and required libraries. A project is always kept in its own Windows folder. It holds the names and locations of all files belonging to the project. It's possible to create a project from scratch, but we've saved you time by creating a sample project that you can use over and over for your own programs. You will find it in the c:\Irvine\Examples directory, and its name is Project_Sample.
This program is called a template because you can use it as a starting point to write your own programs. All you would do is change the comments, and add your own code and variables. Build the ProgramNext, you will build (assemble and link) the sample program. Do one of the following:
In the output window at the bottom of the Visual C++ Express window, you should see messages similar to the following, indicating the build progress: 1>------ Build started: Project: Project, Configuration: Debug Win32
------ 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 ProgramSelect 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. ) You have just run your first Assembly Language program. Press any key to close the Console window.
Step 5: Running the Sample Program in Debug ModeIn this step, you will set a breakpoint inside the sample program. Then you will use the Visual C++ Express debugger to step through the program's execution one statement at a time.
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 BreakPointIf 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.
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 ProgramsSuppose 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.
Adding a File to a ProjectThere are two ways to add an existing assembly language file into an open project:
Try inserting the file c:\Irvine\Examples\ch03\AddSub.asm into your project right now. Next, remove the main.asm file from the project. Next, 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 shown here:
When you press a key, the console window will close. Return to the top of this page, or read about Project Properties settings. (End of Required Setup Information)Building 16-bit Applications (Chapters 12-16)Only Chapters 12 through 16 require the building of 16-bit applications. Except for a few exceptions, which are noted in the book, your 16-bit applications will run under Windows XP. If you plan to build 16-bit applications, you need to add two new commands to the Tools menu in Visual C++ Express (or Visual Studio). To add a command, select External Tools from the Tools menu. The following dialog will appear, although many of the items in your list on the left side will be missing: Step 1: Create the Build 16-bit ASM CommandClick the Add button and fill in the Title, Command, Arguments, and Initial directory fields as shown in the screen snapshot. If you click the buttons with arrows on the right side of the Arguments and Initial directory fields, a convenient list appears. You can select an item without having to worry about spelling: Click the Apply button to save the command. Step 2: Create the Run 16-bit ASM CommandClick the Add button again, and create a new command named Run 16-bit ASM: Click the OK button to save the command and close the External Tools dialog. Testing Your new 16-Bit CommandsTo test your new 16-bit commands, open the file named 16-bit.asm from the ch03 folder in the book's example programs. Select Build 16-bit ASM from the Tools menu. The following command window should appear, showing the successful execution of the assembler and linker, followed by a listing of all files related to this program: Press a key to close the window. Next, you will run the program. Select Run 16-bit ASM from the Tools menu. The following window will appear, although the contents of all registers except EAX will be different: Press a key to close the window. You have completed the setup for building and running 16-bit assembly language programs. Project Properties Settings (Optional Topic)We thought you might like to know more about how Visual C++ projects are set up for assembly language programs. If so, we will walk you through the important parts of the project configuration. Assuming that our sample project is still open, select Project Properties from the Project menu. Expand the entry under Configuration Properties. Then expand the entry named Microsoft Macro Assembler 8.0. This is what you should see: Click the entry named General under Microsoft Macro Assembler 8.0. Notice that the Include Paths option has been set to the c:\Irvine directory. This tells the assembler where to find files having a filename extension of ".inc". Here is a sample: Find the Linker entry under Configuration Properties. Select the Input entry, and notice that two filenames have been added to the Additional Dependencies entry. The user32.lib file is a standard MS-Windows file. The irvine32.lib file is the link library file supplied with this book. There must be at least one space separating the file names: Next, select Linker under Configuration Properties, and then select General. The Additional Library Directories option equals c:\Irvine. so the linker can find the Irvine32.lib library file: Select Debbuging under Linker, under Configuration Properties. Notice that Generate Debug Info has been set to Yes: Select System under the Linker entry. Notice that the SubSystem option has been set to Console: We use the Console setting because assembly language programs usually write their output to a text console window. (This is the window you see when running cmd.exe from the Start > Run menu in Windows XP.) Click the OK button to close the Project Property Pages window. Creating a Project from ScratchYou do not have to create your own projects completely by yourself. Quite frankly, it's a lot of work. We've placed a copy of the Project_sample project in each folder of the book's example programs. You can just add your own program to one of these projects. But if you're one of those brave souls who absolutely must learn how to do things yourself, read on: Here are the steps to create new project from the start. We assume that your project will be named MyProject and will be saved in the c:\temp directory. The commands are a little different, depending on which software you use: Visual C++ Express1. Select New from the File menu, and select Project. 2. In the New Project window, select General, and select Empty Project as the project type: 3. Click the OK button to create the empty project. Visual Studio
Both Visual Studio and Visual C++ Express
Click the OK button to close this window. 7. Next, you need to add some customizations. We will assume you installed the book's files in the c:\Irvine directory. Make all changes shown in the Project Properties Settings section of this document. If you installed the book's sample programs in some other location than c:\Irvine, you'll need to make appropriate changes to the project properties. 9. Select Build Solution. If your Output window is similar to the following message, you did everything right: 1>------ Build started: Project: MyProject, Configuration: Debug Win32 1>Linking... 1>Embedding manifest... 1>Build log was saved at "file://c:\temp\MyProject\Debug\BuildLog.htm" 1>MyProject - 0 error(s), 0 warning(s) ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped Congratulations! You have successfully built a MASM project from scratch. Found an error in this document? Please email me immediately!
Return to the top of this document
Generating a Source Listing FilePrior to 7/26/06, the sample C++ projects in the book's download file do not generate source listing files. Here's how to change that behavior in a single project: Open the project. From the menu, select Project, select Project Properties. In the list box, select Microsoft Macro Assembler, then select Listing File. Set the Assembled Code Listing file option to $(InputName).lst . Return to the top of this document
| ||||||||||||||||||||||||||