Docsity

MASM Code View-Assembly Language, Microprocessors and Computer Architecture-Lab Mannual, Exercises of Computer Architecture and Organization

Toggle sidebar
bg1
2
EXPERIMENT NO 01
Familiarity with MASM and CodeView
1. Objectives
Be able to configure PWB/MASM to produce executable programs with Codeview
debugging support.
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 ar e the Microsoft Macro Assem bler (MASM),
Codeview, and Program mer’s W ork Bench. MASM is the assem bler, which plays a role
similar to a com piler in translating your text-b ased source code into the binary code of a
computer. Translating assem bly language source code into the equivalent binary m achine
code is a much simpler task than translating a program in a high level language. Therefore an
assembler is a m uch simpler program than a co mpiler. The assem bler translates source code
on a statem ent by statem ent basis, with each source statem ent literally specifying an
instruction. One result of this is that the assembler can produce a “listing” file (.lst) that shows
your assem bly code side-by-side with the m achine 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 m odify m emory, and view and m odify registers as your
program runs. The Program mer’s W orkbench is the developm ent environm ent 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.
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download MASM Code View-Assembly Language, Microprocessors and Computer Architecture-Lab Mannual and more Exercises Computer Architecture and Organization in PDF only on Docsity!

EXPERIMENT NO 01

Familiarity with MASM and CodeView

1. Objectives

 Be able to configure PWB/MASM to produce executable programs with Codeview debugging support.

 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 Assem bler (MASM), Codeview, and Program mer’s W ork Bench. MASMis the assem bler, which plays a role similar to a com piler in translating your text-based source code into the binary code of a computer. Translating assem bly language source code into the equivalent binary m achine code is a much simpler task than translating a program in a high level language. Therefore an assembler is a m uch simpler program than a compiler. The assem bler translates source code on a statem ent by statem ent basis, with eachsource statem ent literally specifying an instruction. One result of this is that the assembler can produce a “listing” file (.lst) that shows your assem bly code side-by-side with the m achine 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 m odify m emory, and view and m odify registers as your program runs. The Program mer’s W orkbench is the developm ent environm ent that ties everything together, much like any developm ent 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 Program mer’s W orkBench or PW B isaccessed from the DOS com mand line by typing PWB (or you may use the option in DOSSHELL). The PWB program coordinates the assembly language program ming task by allowing access to the editor, online help, assembler, and CodeView for debugging. The MASM group is an integrated assem bly language development package.

The CodeView feature displays the program in symbolic form and allows the program to be executed an instruction at a tim e, by groups of instructions, or com pletely. (you’ll understand what “sym bolic form” means laterwhen 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 PW B program by running file PWB.exe from C:\m asm 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.

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)?

Does the change in the IP make sense? Explain. (To verify this consider what role the IP register plays and either look at the hex listing of the MOV instruction in the .LST file, or look up the instruction in your text).

3. Experimental Work

Part 1: Use the sample program example1.asm and print out the following on the screen:

Hello World!

Use Codeview to debug code of example1.

Part 2: Repeat step1 though 5 for example2.

Example 1

title Hello World Program (hello.asm)

; This program displays "Hello, world!"

.model small ;Identifies type of memory model to use

.stack 100h ; Identifies size of stack segment

.data ;Contains all variables for program msg by te 'Hello World!',0Ah,0Dh,'$'

.code ;Contains all code from program main proc mov ax,@data ;Required to setup the data segment in the ds register. mov ds,ax

mov ax,0900h

mov dx,offset msg int 21h

mov ax,4C00h ;Required to terminate program normally int 21h main endp end main

Example 2

TITLE Add and Subtract (AddSub.asm)

; This program adds and subtracts 16-bit numbers ; and stores the sum in a variable.

.model small ;Identifies type of memory model to use

.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