CS-220, Sections 50, 51 Laboratory Exercise # 2 2-9-06, Report Due Date: 2-16-06 In this laboratory exercise you will enter, assemble, link, and run your first 80X86 assembly language program, both from a DOS "Command Prompt" window and from the Microsoft Visual Studio .NET Integrated Development Environment. The program is given at the end of this handout. At the time this is being written, all of the PC computers in the Pod labs have the MASM v6.11 system and Microsoft Visual Studio .NET installed. Instructions are given below on how to use the system. It is assumed that you have a formatted diskette in Drive A which will be used to hold all of your program files. If you wish, you may copy your program file to the C:\TEMP directory on the computer you're working with, but be aware that that directory of all the public computers is purged every day, so that any work you want to take with you should be copied to a diskette, CD-ROM, or thumb drive before you leave the lab. PART A. PREPARING ASSEMBLY LANGUAGE PROGRAMS WITH MICROSOFT'S MASM v6.11 ASSEMBLER FROM THE COMMAND LINE 1. Get a DOS "Command Prompt" Window. Select "Start / Run" from the Windows Task Bar, and type in 'cmd' --> a DOS Window with the DOS prompt C:\> 2. Change to the directory with the MASM programs. C:\> cd\masm611\binr 3. Run the batch file that sets up the path correctly. C:\MASM611\BINR> new-vars 4. Change to the floppy disk drive where your programs will be stored. C:\MASM611\BINR> a: 5. Run the DOS editor program to prepare your source program (e.g. lab2.asm). A:\> edit lab2.asm (If you feel more comfortable with one of the Windows editors, such as Notepad, Wordpad, or Word, you may use them. Just be sure that you save your work as a text file--Notepad does that automatically. The text file should be saved with an extension .asm) Enter the assembly language program given at the end of this handout. Try to become familiar with the features of the editor. When you are done and certain that there are no mistakes, save your program and exit the editor. To do that with the DOS editor, you can hit <alt> f, followed by s to save the program, then <alt> f, followed by x to exit. 6. Assemble and link the program, requesting an LST file. A:\> ml /Fl lab2.asm This will generate the following output (if there are no errors): Microsoft(R)Macro Assembler Version 6.14.8444 Copyright(C) 1981-1997. All rights reserved. Assembling: lab2.asm Microsoft(R)Segmented Executable Linker Version 5.31.009 July 13 1992 Copyright(C)Microsoft Corp 1984-1992. All rights reserved. Object Modules [.obj]: lab2.obj Run File [lab2.exe]: "lab2.exe" List File [nul.map]: NUL Libraries [.lib]: Definitions File [nul.def]: [6A. If the system can't find the assembler and linker, you will have to change the path manually. You can do so by entering the following at the DOS prompt: PATH=C:\WINDOWS\SYSTEM32;C:\WINDOWS;C:\MASM611\BIN;C:\MASM611\BINR;
After you have done that, return to step 6.] 7.If there are errors, repeat Step 5 to correct the errors, then Steps 6 and 7. 8.After the program assembles and links without errors, run the program. A:\> lab2 9. The output of the program should be: Welcome to CS-220. A:\> Be sure to have your lab instructor see that the program assembled, linked, and ran correctly. PART B. CONFIGURING VISUAL STUDIO .NET TO BUILD MASM ASSEMBLY LANGUAGE PROGRAMS 1. You will be working out of your computer's C:\TEMP directory, so first copy the makemasm611.bat file into that directory. This is a text file that can be otbained from the following web page: http://www.cs.binghamton.edu/~reckert/220/makemasm611-bat.html The best way to do this is to copy the text into Notepad and then save the file as "makemasm611.bat". To force Notepad to use that exact name, include the quote marks when you give the file name in the File/Save Dialog Box. This batch file contains the commands that will be needed to assemble and link your assembly language programs from the Visual Studio .NET IDE. Any assembly language source files you will be assembling should also be put into this same C:\TEMP directory. 2. Get into the Microsoft Visual Studio .NET Integrated Development Environment. "Start" | "All Programs" | "Microsoft Visual Studio .NET" and click on "Microsoft Visual Studio .NET" 3. Add and "External Tool" to assemble and link assembly language programs from Visual Studio From the VS .NET main menu, "Tools" | "External Tools" | "Add" 4. In the resulting Dialog Box enter the following: Title: Build 16-bit MASM Command: c:\masm\makemasm611.bat Arguments: $(ItemFilename) Initial Directory $(ItemDirectory) Click the "OK" button and notice that when you pull down the "Tools" Menu, the "Build 16-bit MASM" tool appears. 5. Load the lab2.asm assembly language program from Visual Studio "File" | "Open" | "File" and navigate to the directory that contains lab2.asm Double click on the lab2.asm file -- it will be loaded into Visual Studio 6. Build the lab2.asm program "Tools" | "Build 16-bit MASM" Notice that this brings up a DOS Command Window, loads the file, and assembles and links the program at the prompts. You will need to respond to the four prompts by hitting the <Enter> key. If you now look in the directory that contains the lab2.asm, you should find the lab2.obj, lab2.lst, and lab2.exe files produced by the build process. Be sure to show your lab instructor that you can use your new Visual Studio Build 16-bit MASM611 tool and that it works. PART C. CONFIGURING VISUAL STUDIO .NET TO DEBUG MASM ASSEMBLY LANGUAGE PROGRAMS In this part of the lab you will add a second tool to Visual Studio .NET. This tool will be useful for next week's lab. It will allow you to use the DEBUG program from the Visual Studio environment to debug your assembly language programs. 1. From the Visual Studio .NET environment, add another external tool Title: Debug 16-bit MASM Command: c:\windows\system32\debug.exe Arguments: Initial Directory $(ItemDirectory) Be sure to check the "prompt for arguments" text box below these text boxes. Click the "OK" button and notice that when you pull down the "Tools" Menu, a new "Debug 16-bit MASM" tool appears. 2. Use the new tool to debug the lab2.exe program created in Part B "Tools" | "Debug 16-bit MASM" In the resulting "Debug 16-bit MASM" dialog box, enter lab2.exe and hit "OK" Notice that a DOS Command window comes up with a "-" prompt. As we shall see in the next lab, that is the DEBUG program's prompt. Just to see that your lab2.exe executable is there and being debugged, type in the letter u. Notice that the first several machine language instructions of the program are displayed. To run the program type in the letter g. 3. Exit the DEBUG program At the DEBUG "-" prompt, type the letter q. The Command Window goes away 4. Close Visual Studio .NET The last thing you need to do is to print out the assembled listing (the .LST file). One way of doing that is to use the Windows Wordpad program on a computer system that has a printer attached-- Example: a) Launch Wordpad b) Open A:lab2.lst c) Edit Pull-Down / Select All d) Format Pull Down / Font e) Change to Font: "Courier New", Size: "10" f) File Pull-Down - Print Preview g) Make sure text (width) fits on page; if not change to Size: "8" h) File Pull-Down / Print / OK Turn in the printed copy of your LAB2.LST on or before the due date. THE LAB2.ASM PROGRAM: ----------------------------------------------------------------------- ;************************************************* ; This program outputs a message to the screen. * ; Your Name * ; CS 220 Your Section * ;************************************************* TITLE First Assembly Language Program PAGE 60,132 .MODEL SMALL ;1 code segment, 1 data segment .STACK 64 ;Reserve 64 words of stack space .DATA ;Following will be in data segment msg db 'Welcome to CS-220$' ; define the msg .CODE ;Following will be in code segment main proc far mov ax,_DATA ;Name of data segment mov ds,ax lea dx,msg ; Output... mov ah,9 ; the msg int 21h mov ax,4c00h ;Return to DOS using int 21h... int 21h main endp end main