This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

3. Familiarity with MASM, Codeview, Addressing Modes Part I: Background The Microsoft Assembler package, MASM, is a programming environment that contains two major tools: the assembler/linker and the CodeView debugger. The assembler/linker translates x86 instructions to machine code and produces a ".exe" file that can be executed under DOS. The CodeView tool is an enhanced version of DEBUG with a graphical interface that also handles 32 bit instructions. A help program called 'qh' is a DOS-based utility that provides documentation on MASM and CodeView. Appendix A of this lab has some tips concerning MASM installation on your PC. Objectives: Learn to: A. Use the MASM program to assemble and link a program. B. Use CodeView to debug and execute an assembler language program. C. Explore some of the addressing modes available in the x86 instruction set. Pre-Lab Read Chapter 3 and Appendix C in the Irvine Textbook. Chapter 3 gives a good introduction to the Microsoft assembler, basic arithmetic instructions (add, subtract, increment, decrement), and basic addressing modes. 1. Answer Question 41 in the Irvine Textbook. 2. Answer Question 43 in the Irvine Textbook. 3. Explain what direct addressing is and give an example. 4. Explain what indirect addressing is and give an example. Lab A.1 The Assembly Language Process Using the Command line The following section explains how to assemble and link a file using the command line from a DOS window. The steps are:1. Create or edit the source code (.asm file) using any ASCII text editor. Warning -- the file must be saved in an ASCII format - some editors like 'winword', or 'word' store the file by default in a binary format. To save as an ASCII format in some of the microsoft editors, select output type as *.TXT but specify the full file name as myfile.asm (the .asm extension should be used for assembly language files). A program called 'PFE32' (Programmer's File Editor) is installed on the PCs in the Micro I lab and is a good choice for a text editor. 2. Invoke the masm program to assemble the file and produce a .obj file and optionally, a .lst file. 3. Invoke the link program to produce a .exe program (or a .com program via a command line argument). Assume we have an assembly language file called test.asm that has been saved in ASCII format. Open a DOS window. To assemble the file, change to the directory where the file is via the 'cd' command, and type: C:\> masm test If assembly is successful, this will produce a file called test.obj. If errors are present, you will be given the line numbers where the syntax errors ocurred. You can also produce a listing file (.lst) which shows opcodes for all instructions via: C:\> masm test,test, test It is a good idea to always create a .lst file output. A .exe file must be created from the .obj file via the link program. Type: C:\> link test You will be prompted for file names for the Run file, List file, libraries, and Definitions file. Just hitting <enter> for each choice will use the defaults. This will produce a test.exe file which can then be executed. You can also produce the .exe file with no prompting from the link program via: C:\> link test,,,,, Use 5 commas after filename (test) to provide defaults for all other choices. Using the command line for masm/link is probably the easiest thing to do if you are only assembling/linking one source file. Most of your labs will only consist of one source file. Section B discusses how to use a debugger called 'codeview'. In order to view the source code of your program within the 'codeview' debugger, you need to use some command line switches with the masm and link programs in order to include debugging information. The switches are "/zi' for masm, and "/co' for link as shown below: C:\> masm /zi test,test, test C:\> link /co test,,,,, You can get help on many topics (MASM, codeview, the x86 instruction set, etc) by typing 'qh' (Quick Help) in a command window - this brings up the help files that included with the MASM installation. You should try this at least once to see what is available.A.2 A Sample Program Use a text editor and type in the following program (and yes, you have to type it in instead of copying it from somewhere because you will probably make mistakes in typing it, and this will force you to deal with MASM syntax errors). Example 4.1 .model small .586 .stack 100h .data byte1 db 1 byte2 db 0 word1 dw 1234h word2 dw 0 string db "This is a string", "$" ;---- this is a comment .code MAIN PROC Mov ax, @data Mov ds, ax Mov ax,0 Mov AL, byte1 Mov byte2,AL Mov cx, word1 Mov word2, cx Mov ax, 4c00h Int 21h Main endp End main Look at Example 1 (The Hello World program) in Irvine, Chapter 3 for an explanation of what the various assembler directives mean. There are some differences between this program and the Hello World program:1. The ".586" assembler directive allows us to use Pentium instructions in this program. By default, only instructions that were included in the original 8086 can be used. Later on, this will prove to be useful so go ahead and use it. 2. This program does not use a "Title" assembler directive -- this is optional. 3. The "dw" assembler directive specifies that a word of storage be allocated (1 word = 2 bytes = 16 bits). Assemble and link this program using MASM. Make sure that you produce a listing (.lst) file. Lab Question 1: Open the listing (.lst) file with a text editor. A. Give the machine code for the instruction "mov ax,0" and the instruction "mov ax, 4c00h". From these two sets of machine codes, what is the OPCODE and what is the DATA for the instruction. B. Look at the machine code for the instruction "mov ax, @data". You will see "----" in the machine code. This is because the symbol "@data" represents the segment address of the data segment for this program. This value is NOT KNOWN until the program is loaded into memory. Why are the first two statements in this program needed? (mov ax, @data and mov dx,ax) What do they accomplish? How could our program malfunction if these were not included?B. Debugging Programs Using Code View Codeview (cv.exe) is an external debugger that offers many more features than the 'debug.exe' program. You can debug programs simply by using debug.exe, but Codeview allows you easily track both memory and register changes. It is recommended that you use Codeview for


View Full Document

MSU ECE 3724 - Familiarity with MASM

Documents in this Course
Timers

Timers

38 pages

TEST 4

TEST 4

9 pages

Flags

Flags

6 pages

Timers

Timers

6 pages

Timers

Timers

54 pages

TEST2

TEST2

8 pages

Load more
Download Familiarity with MASM
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Familiarity with MASM and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Familiarity with MASM 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?