task 1- getting started with masm and visual studio 2010

Upload: aquadestructor

Post on 02-Jun-2018

235 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Task 1- Getting Started With MASM and Visual Studio 2010

    1/26

    Getting Started with MASM and Visual StudioThe book's example programs in Chapters 1-14 have been successfully tested in Windows!" #$-bit %ista and the #$-bit version of Windows & (n the other hand" many programsin Chapters 1)-1& will not run in any *icrosoft (+ later than Windows , " because theyrely on direct access to hardware and system memory .ou cannot directly run 1/-bit

    applications in any /4-bit version of Windows

    Required Setup for 32-bit Applications0irst" you must install %isual +tudio $ 1 and select the C22 language option %+ $ 1and %isual C22 $ 1 3xpress both include the current version of the *icrosoftssembler .ou can verify that the *icrosoft ssembler is installed by looking for thefile ml.exe in the \vc\bin folder of your %isual +tudio installation directory" such asc:\Program iles\!icrosoft "isual Studio #$.x\vc\bin.

    %sing "isual Studio &xpress' (ou must do t)e follo*ing in order to see t)e samemenu options as t)e users of "isual Studio professional: from t)e Tools menu+select Settings + and select Expert Settings

    Next: Install the Book's Example Programs

    The latest copy of the book's link libraries and example programs have been copied tothe c:\,rvine folder

    Check that the following files are copied into the c:\,rvine directory5

    ilename escription

    cmd exe +hortcut to the Windows command-line interpreter 6namedcmd exe7

    8raphWin inc 9nclude file for writing Windows applications

    9rvine1/ inc 9nclude file used with the 9rvine1/ link library 61/-bit applications7

    9rvine1/ lib 1/-bit link function library used with this book

    9rvine#$ inc 9nclude file used with the 9rvine#$ link library 6#$-bit applications7

    :ink1/ exe 1/-bit linker

    9rvine#$ lib #$-bit link function library used with this book

    ;ser#$ lib ed include file" used by 9rvine#$ inc

    make1/ bat

  • 8/11/2019 Task 1- Getting Started With MASM and Visual Studio 2010

    2/26

  • 8/11/2019 Task 1- Getting Started With MASM and Visual Studio 2010

    3/26

    Building a Sample Assem"l& anguage Program

    Bow you're ready to open and build your first pro ect

    (pening a Pro)e t

    %isual +tudio and %isual +tudio 3xpress reAuire assembly language source files to belongto a project " which is a kind of container pro ect holds configuration information suchas the locations of the assembler" linker" and reAuired libraries pro ect has its ownfolder" and it holds the names and locations of all files belonging to it We have created asample pro ect folder in the c:\Irvine\cxamples\ch03 directory" and its name is Project

    Do the following steps" in order5

    1 +tart %isual +tudio$ 0irst you will open an existing %isual +tudio pro ect file 9f you're using %isual

    +tudio" select 0pen Pro4ect from the 0ile menu (r" if you're using %isual +tudio3xpress" select 0pen " and select Pro4ect5Solution.

    # Bavigate to the c:\,rvine\&xamples\c)$3 folder and open the filenamed Pro4ect.sln

    4 9n the Solution Explorer window" you will see the word !ro ect This is the nameof a %isual +tudio pro ect

    ) Bext" you need to add a source code file named main.asm to the pro ect To dothat" right-click on Pro4ect " select Add " select &xisting ,tem " select main.asm "and click the Add button to close the dialog window 6.ou can use this seAuenceof commands in the future to add any asm file into a pro ect 7

    / Bext" you will open the main asm file for editing Double-click the filenamed main.asm to open it in the editing window 6%isual +tudio users may see a

    popup dialog asking for the encoding method used in the asm file ust click the(? button to continue 7

    Tip: 9f the Solution Explorer window is not visible" select Solution Explorer fromthe View menu lso" if you do not see main.asm in the +olution 3xplorer window" itmight be hidden behind another window To bring it to the front" click the Solution

    Explorer tab from the tabs shown along the bottom of the window

    .ou should see the following program in the editor window5

  • 8/11/2019 Task 1- Getting Started With MASM and Visual Studio 2010

    4/26

    TITLE MASM Template (main.asm)

    ; Description:;; Revision date:

    INCL DE Irvine!".inc

    .data m#Messa$e %&TE 'MASM pro$ram e ample' *d+ *a+ *

    .code main ,R-C

    call Clrscr

    mov ed - SET m#Messa$e call /riteStrin$

    e it main END,

    END main

    :ater" we'll show you how to copy this program and use it as a starting point to write your own programs

    Build the Program

    Bext" you will build 6assemble and link7 the sample program +elect 6uild Pro4ect fromthe

  • 8/11/2019 Task 1- Getting Started With MASM and Visual Studio 2010

    5/26

    9f you do not see these messages" the pro ect has probably not been modified since it waslast built Bo problem-- ust select Rebuild Pro4ect from the

  • 8/11/2019 Task 1- Getting Started With MASM and Visual Studio 2010

    6/26

    $ To begin stepping through your program in Debug mode" press the 01 key# yellow arrow will appear next to the first program statement 6 call Clrscr 7 The

    arrow indicates that the statement is next to be executed4 !ress the 01 key 6called Step Over 7 to execute the current statement Continue

    pressing 01 until the program is about to execute the exit statement

    ) small black window icon should appear on your Windows status bar (pen itand look at the contents of the Command window .ou should see the wordsE* +* program exampleE in the window

    / !ress 01 one more time to end the program

    *egisters

    9f you want to display the C!; registers" do the following5 +tart debugging the program"then select in!ows from the "e#u$ menu +elect %e$isters from the drop-down list The

    bottom window will display the register contents Gight click this window and check theitem &la$s to enable the display of conditional flags

  • 8/11/2019 Task 1- Getting Started With MASM and Visual Studio 2010

    7/26

    .ou can interrupt a debugging session at any time by selecting Stop "e#u$$in$ from theDebug menu .ou can do the same by clicking the blue sAuare button on the toolbar Toremove a breakpoint from the program" click on the red dot so that it disappears

    Setting a BreakPoint

    9f you set a breakpoint in a program" you can use the debugger to execute the program afull speed 6more or less7 until it reaches the breakpoint t that point" the debugger dropsinto single-step mode

    1 Click the mouse along the border to the left of the call Write+tring statement large red dot should appear in the margin

    $ +elect +tart Debugging from the Debug menu The program should run" and pauseon the line with the breakpoint" showing the same .ellow arrow as before

    # !ress 01 until the program finishes

    .ou can remove a breakpoint by clicking its red dot with the mouse Take a few minutesto experiment with the Debug menu commands +et more breakpoints and run the program again 0or the time being" you can use the 011 key to step through the programin the same way the 01 key did

    Building and *unning (ther Programs

    +uppose you want to run another example program" or possibly create your own program.ou can either edit and modify main asm" or you can remove main asm from the pro ectand insert some other asm file into the pro ect

    To remove a program from a pro ect without deleting the file" right-click its namein the Solution Explorer win!ow 9n the context menu" select &xclude fromPro4ect 9f you change your mind and decide to add it back to the pro ect" right-click in the same window" select Add+ select &xisting item+ and select the file youwant to add

    To remove a program from a pro ect and delete the source code file" select the filewith the mouse and press the el key (r" you can right-click the file name andselect Remove.

    Adding a .ile to a Pro)e t

    The easiest way to add an assembly language source file to an open pro ect is to drag itsfilename with the mouse from a Windows 3xplorer window onto the name of your pro ect in the +olution 3xplorer window reference to the file 6not a copy7 will beinserted in your pro ect's directory Try this now5

    1 Gemove the main asm file from your pro ect$ dd a reference to the file c5F9rvineF3xamplesFch #F dd+ub asm to the pro ect#

  • 8/11/2019 Task 1- Getting Started With MASM and Visual Studio 2010

    8/26

    @ere is what you should see in the Console window" except that only your 3 registerwill have the same value as ours5

    When you press a key" the console window will close

    +op&ing a sour e ,ile

    9f you want to make a copy of an existing file" use Windows 3xplorer to copy the file intoyour pro ect directory Then" right-click the pro ect name in +olution 3xplorer" selectdd" select 3xisting 9tem" and select the filename

    6uilding #8-bit Applications 9 )apters # -#;