MASM-Assembly Language Programming-Lab Manual, Exercises of Assembly Language Programming

Prof. Abhay Aggrawal provided this lab handout for assistance at Birla Institute of Technology and Science for lab of Assembly Language Programming. It includes: Procedure, MASM, Assembler, programming, Integrated, Debugging, Mouse, PWB, Dosshel, Values, Menu

Typology: Exercises

2011/2012

Uploaded on 07/26/2012

parina
parina 🇮🇳

4.4

(67)

222 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Use CodeView to debug and execute an assembler language program
Be able to use Codeview to view register contents, memory contents, and execution
point. Be able to use Codeview to predict the behavior of the next instruction.
2. Basic Information
The three tools you will be working with are the Microsoft Macro Assembler (MASM), Codeview, and Programmer’s Work Bench. MASM is the assembler, which plays a role similar to a compiler in translating your text-based source code into the binary code of a computer. Translating assembly language source code into the equivalent binary machine code is a much simpler task than translating a program in a high level language. Therefore an assembler is a much simpler program than a compiler. The assembler translates source code on a statement by statement basis, with each source
statement literally specifying an instruction. One result of this is that the assembler can produce a “listing” file (.lst) that shows your assembly code side-by-side with the machine code generated. This list file can be a useful tool in understanding what is going on and can sometimes be used to aid in debugging.
Codeview is the debugger provided with the Microsoft Assembly Language development system. It is a powerful debugger that allows you to run and single step your program. You may set break-points, view and modify memory, and view and modify registers as your program runs. The Programmer’s Workbench is the development environment that ties everything together, much like any development environment such as Visual Studio, Borland or Watcom’s IDE (Integrated Development Environment), or the GNU tools on Linux. Unlike Visual Studio, PWB is a text based development
environment running under MS-DOS.
2.1 Procedure
The Microsoft MASM assembler programming package is actually a programming
environment that contains four major features: the assembler and linker; complete online
help with QuickHelp; Programmer’s WorkBench, and CodeView.
The assembler and linker program is Microsoft version 6.1 that is called ML.EXE on the
distribution disk. The assembler has all the features of earlier versions and is completely
compatible with them. The ML.EXE program is normally accessed through
Programmer’s WorkBench and not directly from the DOS command line.
The Programmer’s WorkBench or PWB is accessed from the DOS command line by
typing PWB (or you may use the option in DOSSHELL). The PWB program coordinates
the assembly language programming task by allowing access to the editor, online help,
assembler, and CodeView for debugging. The MASM group is an integrated assembly
language development package.
The CodeView feature displays the program in symbolic form and allows the program to
be executed an instruction at a time, by groups of instructions, or completely. (you’ll
understand what “symbolic form” means later when we contrast CodeView to the DOS
utility DEBUG which doesn’t support symbolic debugging). Debugging is accomplished
by the display of the registers and sections of memory in various windows. Note that a
mouse is not required for using the PWB package, but is highly recommended.
2.2 Using PWB
Figure1 shows the startup screen in PWB. Across the top is the menu bar that contains 9 pulldown menus that access various features of PWB. As with all Microsoft programs, the mouse is used to activate a pulldown menu or if no mouse is available, the alternate key and first letter of the menu name.
Figure 1
docsity.com
pf3
pf4

Partial preview of the text

Download MASM-Assembly Language Programming-Lab Manual and more Exercises Assembly Language Programming in PDF only on Docsity!

 Use CodeView to debug and execute an assembler language program

 Be able to use Codeview to view register contents, memory contents, and execution

point. Be able to use Codeview to predict the behavior of the next instruction.

2. Basic Information

statement literally specifying an instruction. One result of this is that the assembler can produce a “listing” file (.lst) t^ The three tools you will be working with are the Microsoft Macro Assembler (MASM), Codeview, and Programmer’s Work Bench. MAShat shows your assembly code side-by-side with the machine code generated. This list file can be a useful tool in understanding what is going on and can sometimes be used to aid in debugging.M is the assembler, which plays a role similar to a compiler in translating your text-based source code into the binary code of a computer. Translating assembly language source code into the equivalent binary machine code is a much simpler task than translating a program in a high level language. Therefore an assembler is a much simpler program than a compiler. The assembler translates source code on a statement by statement basis, with each source environment running under MS-DOS.^ Codeview is the debugger provided with the Microsoft Assembly Language development system. It is a powerful debugger that allows you to run and single step your program. You may set break-points, view and modify memory, and view and modify registers as your program runs. The Programmer’s Workbench is the development environment that ties everything together, much like any development environment such as Visual Studio, Borland or Watcom’s IDE (Integrated^ Development Environment), or the GNU tools on Linux. Unlike Visual Studio, PWB is a text based development

2.1 Procedure

The Microsoft MASM assembler programming package is actually a programming

environment that contains four major features: the assembler and linker; complete online

help with QuickHelp; Programmer’s WorkBench, and CodeView.

The assembler and linker program is Microsoft version 6.1 that is called ML.EXE on the

distribution disk. The assembler has all the features of earlier versions and is completely

compatible with them. The ML.EXE program is normally accessed through

Programmer’s WorkBench and not directly from the DOS command line.

The Programmer’s WorkBench or PWB is accessed from the DOS command line by

typing PWB (or you may use the option in DOSSHELL). The PWB program coordinates

the assembly language programming task by allowing access to the editor, online help,

assembler, and CodeView for debugging. The MASM group is an integrated assembly

language development package.

The CodeView feature displays the program in symbolic form and allows the program to

be executed an instruction at a time, by groups of instructions, or completely. (you’ll

understand what “symbolic form” means later when we contrast CodeView to the DOS

utility DEBUG which doesn’t support symbolic debugging). Debugging is accomplished

by the display of the registers and sections of memory in various windows. Note that a

mouse is not required for using the PWB package, but is highly recommended.

2.2 Using PWB

Figure1 shows the startup screen in PWB. Across the top is the menu bar that contains 9 pulldown menus that access various features of PWB. As with all Microsoft programs, the mouse is used to activate a pulldown menu or if no mouse is available, the alternate key and first letter of the menu name.

Figure 1

Step 1: Activate the PWB program by running file PWB.exe from C:\masm direstory. Once PWB is activated select the File pulldown menu with the mouse or by the alternate plus F key combination. Next select New to start a new file.

You are now ready to begin entering an assembly language program. Type the program listed in Example 1 This program will be used through much of this experiment to learn how to use PWB and its features. Before entering the program, it is a good idea to name it at this point. To name the program select Save from the File pulldown menu. Enter the desired file name with the extension of .ASM for an assembly language source file. Save the program in directory C:\masm. Once the name and path is selected, choose OK After this the PWB program returns to the main edit screen so the programcan be entered.

Step 2: From the File pulldown menu select DOSSHEL. To assemble the code use the following command at the DOS command prompt.

This command will create example1.obj (machine code).^ Masm/zi example

Step 3: If there were no errors in the file, then invoke the Microsoft linker to generate the executable (.EXE) file by entering the following at the DOS command prompt:

This command will create EXE file example1.exe (executable file).^ Link/co example

Step 4: If there were no errors during the Linking process. Then run the file example1.exe by entering the file name at DOS command prompt and view the output.

Step 5: To debug your assembly code use CodeView by entering the following at the DOS command prompt:

CV example

This command will open the new window. CodeView should launch with your source code visible in a source window. Use the Windows menu to open a register, source, and memory window. Do this by selecting Windows->Source 1, Windows->Memory 1,

and Windows->Register Since you haven’t begun executing any instructions, your program should be in an initial state. Fill out the following table from the register window:.

AX = DI= BX= CX= DX= SP= BP= SI=

DS = ES = SS = CS =

IP= FL=

Note that the registers in BOLD are variable every time you load the program and these will probably be different every time (these are the segment registers that are so important in the Intel Architecture).

Now hit F10 a single time to single step through one instruction. You should notice changes in the source and register windows.

Which registers changed values?

What are the new values of these registers?

What are the old values (Use the Run->Restart menu to go back and see the old values if

neccessary)?

.stack 100h ; Identifies size of stack segment .data val1 word 1000h val2 word 4000h val3 word 2000h finalVal word? .code main PROC mov ax,val1 ; start with 1000h add ax,val2 ; add 4000h sub ax,val3 ; subtract 2000h mov finalVal,ax ; store the result (3000h) mov ax,4C00h ;Required to terminate program normally int 21h main ENDP end main