0% found this document useful (0 votes)
159 views

Exercises/Experiments Using Masm: Csl331: Microprocessor LAB

The document describes experiments using MASM (Microsoft Macro Assembler) to study assembly language development tools. It discusses editors to write assembly code, assemblers to translate mnemonics to binary codes, linkers to assign memory addresses, and debuggers to load and run programs. The experiments include programs for 16-bit addition, reading and displaying a string, and checking if a string is a palindrome. The document provides the assembly code listings and output for each program.

Uploaded by

Tony Kuttan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views

Exercises/Experiments Using Masm: Csl331: Microprocessor LAB

The document describes experiments using MASM (Microsoft Macro Assembler) to study assembly language development tools. It discusses editors to write assembly code, assemblers to translate mnemonics to binary codes, linkers to assign memory addresses, and debuggers to load and run programs. The experiments include programs for 16-bit addition, reading and displaying a string, and checking if a string is a palindrome. The document provides the assembly code listings and output for each program.

Uploaded by

Tony Kuttan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

CSL331: MICROPROCESSOR LAB

EXERCISES/EXPERIMENTS USING MASM

CSE Department,STM,KANNUR
1
CSL331: MICROPROCESSOR LAB

EXP NO:12 DATE:

STUDY OF ASSEMBLER AND DEBUGGING COMMANDS

Aim:
To Study the MASM Assembler and its Debugging commands.

Assembly Language Development Tools:

1. EDITOR:
It’s a system software (program) which allows users to create a file containing assembly
instructions and statements. Ex: Wordstar, DOS Editor, Norton Editor
 Using the editor, you can also edit/delete/modify already existing files.
 While saving, you must give the file extension as “.asm”.
 Follow the AL syntax while typing the programs
 Editor stores the ASCII codes for the letters and numbers keyed in.
 Any statement beginning with semicolon is treated as comment.
When you typed all your program, you have to save the file on the disk. This file is called
“source” file, having a ‘.asm’ extension. The next step is to convert this source file into a machine
executable ‘.obj’ file.
2. ASSEMBLER:
 An “assembler” is a system software (program) used to translate the assembly language mnemonics
for instructions to the corresponding binary codes.
 An assembler makes two ‘passes’ thro’ your source code. On the first pass, it determines the
displacement of named data items, the offset of labels etc., and puts this information in a symbol
table. On the second pass, the assembler produces the binary code for each instruction and inserts the
offsets, etc., that is calculated during the first pass. The assembler checks for the correct syntax in the
assembly instructions and provides appropriate warning and error messages. You have to open your
file again using the editor to correct the errors and reassemble it using assembler. Unless all the
errors are corrected, the program cannot be executed in the next step.
 The assembler generates two files from the source file; the first file, called the object file having an
extension “.obj” which contains the binary codes for instructions and information about the addresses
of the instructions. The second file is called “list file” with an extension “’.lst”. This file contains the
assembly language statements, the binary codes for each instruction, and the offset for each inst. It
also indicates any syntax errors or typing errors in the source program.

CSE Department,STM,KANNUR
2
CSL331: MICROPROCESSOR LAB

Note: The assembler generates only offsets (i.e., effective addresses); not absolute
physical addresses.

3. LINKER:
 It’s a program used to assign absolute physical addresses to the segments in the “.exe” file, in the
memory. IBM PC DOS environment comes with EXE2BIN loader program. The “.exe” file is
converted into “.bin” file.
 The physical addresses are assigned at run time by the loader. So, assembler does not know about
the segment starting addresses at the time program being assembled.

5. DEBUGGER:
If your program requires no external hardware, you can use a program called debugger to
load and run the “.exe” file.
 A debugger is a program which allows you to load your object code program into system memory,
execute the program and troubleshoot or debug it. The debugger also allows you to look at the
contents of registers and memory locations after you run your program.
 The debugger allows you to change the contents of registers & memory locations and rerun the
program. Also, if facilitates to set up “breakpoints” in your program, single step feature, and other
easy-to-use features.
 If you are using a prototype SDK 86 board, the debugger is usually called “monitor program”. We
would be using the development tool MASM 5.0 or higher version from Microsoft Inc. MASM
stands for Microsoft Macro Assembler. Another assembler TASM (Turbo Assembler) from Borland
Inc., is also available.
How to Write and Execute your ALP using MASM?
Steps to be followed:
1. Type EDIT at the command prompt (C:\>\MASM\). A window will be opened with all the options
like File, Edit etc., In the workspace, type your program according to the assembly language syntax
and save the file with a “.asm” extension. (say test.asm)
2. Exit the Editor using File menu or pressing ALT + F + X.
3. At the prompt, type the command MASM followed by filename.asm (say, test.asm). Press Enter
key 2 or 3 times. The assembler checks the syntax of your program and creates “.obj” file, if
there are no errors. Otherwise, it indicates the error with line numbers. You have to correct the errors
by opening your file with EDIT command and changing your instructions. Come back to DOS

CSE Department,STM,KANNUR
3
CSL331: MICROPROCESSOR LAB

prompt and again assemble your program using MASM command. This has to continue until
MASM displays “0 Severe Errors”. There may still be “Warning Errors”. Try to correct them also.
4. Once you get the “.obj” file from step 3, you have to create the “.exe” file. At the prompt, type the
command LINK followed by “filename.obj” (say, test.obj) and press Enter key. (Note that you have
to give the extension now as “.obj” and not as “.asm”). If there are no linker errors, linker will create
“.exe” file of your program. Now, your program is ready to run.
5. There are two ways to run your program.
a) If your program accepts user inputs thro’ keyboard and displays the result on the screen,
then you can type the name of the file at the prompt and press Enter key. Appropriate
messages will be displayed.
b) If your program works with memory data and if you really want to know the contents of
registers, flags, memory locations assigned, opcodes etc., then type CV test (file name) at the
prompt. Another window will be opened with your program, machine codes, register contents
etc.,
Now, you also get a prompt > sign within CV window. Here you can use “d” command to display
memory contents, “E” command to enter data into memory and “g” command to execute your
program. Also, you can single step thro’ your program using the menu options. In many ways, CV
(Code View) is like Turbo C environment.
Once you are familiar with the architecture and basics of assembly language tools, you can start
typing and executing your program
RESULT
Familiarized Assembler and Debugging commands

CSE Department,STM,KANNUR
4
CSL331: MICROPROCESSOR LAB

EXP NO:13 DATE:

IMPLEMENTATION OF DECIMAL ARITHMETIC OPERATIONS

1) 16 bit addition:

AIM: -
To write an assembly language program for Addition of two 16-bit numbers.

APPARATUS:

1. MASM----1

PROGRAM:

.model small
.data
x db "Enter the first number :$"
y db 0ah,0dh, "Enter the second number :$"
z db 0ah,0dh, "Result is :$"

.code
.startup

print macro a
lea dx,a
mov ah,09h
int 21h
endm

read macro b
mov ah,01h
int 21h
sub al,30h
mov bh,al
endm

print x
read a
mov ch,bh

print y
read b

print z

mov al,bh
add al,ch
mov dl,al
CSE Department,STM,KANNUR
5
CSL331: MICROPROCESSOR LAB

add dl,30h
mov ah,02h
int 21h

.exit
end

Output:

Enter the first number :


Enter the second number :
Result is :

CSE Department,STM,KANNUR
6
CSL331: MICROPROCESSOR LAB

EXP NO:14 DATE:

14.1 READ AND DISPLAY A STRING

AIM: -
To write an assembly language program to read a string and display it

APPARATUS:

1. MASM----1

PROGRAM:
.model small
.data
x db "Enter the string :$"
arr db 20 dup('$')
y db 0ah,0dh, "String is :$"

.code
.startup
print macro a
lea dx,a
mov ah,09h
int 21h
endm
print x
mov si,00h

l1:
mov ah,01h
int 21h
mov arr[si],al
inc si
cmp al,0dh
je l2
jmp l1

l2:
print y

mov si,00h

l3:
mov dl,arr[si]
mov ah,02h
int 21h
inc si
cmp al,0dh
je l4
jmp l3

CSE Department,STM,KANNUR
7
CSL331: MICROPROCESSOR LAB

l4:
.exit
end
Output
Enter the sting : Arun
String is : Arun
RESULT:

MASM program to read and display a string is executed and verified the output

CSE Department,STM,KANNUR
8
CSL331: MICROPROCESSOR LAB

14.2 STRING PALINDROME

AIM:
- To write an assembly language program to check whether the inputted string is palindrome or
not

APPARATUS:

1. MASM----1

PROGRAM:
.model small

.data

x db "Enter the string :$"

y db 0ah,0dh, "Palindrome $"

z db 0ah,0dh, "Not palindrome $"

arr db 20 dup('$')

.code

.startup

print macro a

lea dx,a

mov ah,09h

int 21h

endm

print x

mov si,00h

l1:

mov ah,01h

int 21h

cmp al,0dh

je l2

mov arr[si],al

inc si

jmp l1
CSE Department,STM,KANNUR
9
CSL331: MICROPROCESSOR LAB

l2:

dec si

mov di,00h

l3:

mov al,arr[si]

mov ah,arr[di]

cmp al,ah

jne l4

inc di

dec si

cmp di,si

jl l3

print y

jmp e

l4: print z

e:

.exit

end

Output
Enter the string :
cat Not palindrome
Enter the string : amma
Palindrome
RESULT:

MASM program for palindrome checking of string is executed and verified the output

CSE Department,STM,KANNUR
10
CSL331: MICROPROCESSOR LAB

CSE Department,STM,KANNUR
11

You might also like