Warriors of the Visual Studio, Assemble! (Visual Studio的勇士們,彙編吧!) 原創 2009年07月12日 19:40:00 標籤:彙編 /mic

來源:互聯網
上載者:User
Warriors of the Visual Studio, Assemble! (Visual Studio的勇士們,彙編吧。) 原創  2009年07月12日 19:40:00 標籤: 彙編 / microsoft / express / file / assembly / command
Warriors of the Visual Studio, Assemble!
If you've recently purchased  Assembly Language for Intel-Based Computers, 5th edition, you probably want to get the software set up so you can start working. This tutorial should make the process easier. If you're in a hurry to get started, you only need to read Item 1. Required setup for 32-bit applications Building 16-bit applications (Chapters 12-16) Project properties settings Creating a project from scratch Generating a source listing file Using the Visual Studio debugger MASM syntax highlighting Assembling, linking, and debugging with a batch file

Found an error in this document? Please email me immediately. Except where noted, all instructions in this document apply equally to Visual Studio and Visual C++ Express. Required Setup for 32-bit Applications First, you must install some version of Visual Studio or Visual C++ Express: If you have installed Visual Studio 2008 Professional or Team Suite, these products also contain the Microsoft Assembler 9.0.  If you have installed Visual C++ 2008 Express Service Pack 1, it includes MASM 9.0. If you have installed Visual C++ 2005 Express, you must also download the Microsoft Assembler 8.0
(see below). Downloading Microsoft Express Editions Visual C++ 2008 Express Visual C++ 2005 Express .

You can verify that the Microsoft Assembler is installed by looking for the file ml.exe in the /vc/bin folder of your Visual Studio installation directory, such as c:/Program Files/Microsoft Visual Studio 9.0/vc/bin.

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 Book's Example Programs

Click 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 thec:/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:

Filename

Description

GraphWin.inc

Include file for writing Windows applications

Irvine16.inc

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

Irvine16.lib

16-bit link function library used with this book

Irvine32.inc

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

Link16.exe 16-bit linker

Irvine32.lib

32-bit link function library used with this book

Macros.inc

Include file containing macros (explained in Chapter 10)

SmallWin.inc

Small-sized include file, used by Irvine32.inc

make16.bat Batch file for building 16-bit applications

VirtualKeys.inc

Keyboard code definitions file, used by Irvine32.inc

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 aproject, 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: Start Visual Studio or Visual C++ Express. 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. Navigate to the c:/Irvine/Examples/Project_Sample folder and open the file namedProject.sln. 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 theView 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:INCLUDE Irvine32.inc.datamyMessage BYTE "MASM program example",0dh,0ah,0.codemain PROC    call Clrscr    mov  edx,OFFSET myMessage    call WriteString    exitmain ENDPEND 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...1>Assembling: ./main.asm1>Linking...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. To begin stepping through your program in Debug mode, press the F10 key. A yellow arrow will appear next to the first program statement (call Clrscr).The arrow indicates that the statement is next to be executed. 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. 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. Press F10 one more time to end the program.

Registers

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 Flagsto 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. Click the mouse along the border to the left of the call WriteString statement. A large red dot should appear in the margin. 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. 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 selectRemove. 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: Remove the main.asm file from your project. Add a reference to the file c:/Irvine/Examples/ch03/AddSub.asm

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.