You are on page 1of 29

PART-A

Microprocessors and Microcontrollers Lab Manual

Introduction to MASM/TASM
AIM: To know how to use TASM.

APPARATUS:

S. No APPARATUS Version

1. PC load with Assembler TASM Turbo Assembler 4.1

THEORY:

EDITOR
An editor is a program, which allows you to create a file containing the assembly
language statements for your program. As you type in your program, the editor stores the
ASCII codes for the letters and numbers in successive RAM locations. When you have
typed in all of your programs, you then save the file on a floppy of hard disk. This file is
called source file. The next step is to process the source file with an assembler. In the
TASM assembler, you should give your source file name the extension, .ASM
ASSEMBLER
An assembler program is used to translate the assembly language mnemonics for
instructions to the corresponding binary codes. When you run the assembler, it reads
the source file of your program the disk, where you saved it after editing on the first
pass through the source program the assembler determines the displacement of named
data items, the offset of labels and pails this information in a symbol table. On the
second pass through the source program, the assembler produces the binary code for
each instruction and inserts the offset etc that is calculated during the first pass. The
assembler generates two files on floppy or hard disk. The first file called the object file
is given the extension. OBJ. The object file contains the binary codes for the
instructions and information about the addresses of the instructions. The second file
generated by the assembler is called assembler list file. The list file contains your
assembly language statements, the binary codes for each instructions and the offset for
each instruction. In TASM assembler, TASM source file name ASM is used to
assemble the file. Edit source file name LST is used to view the list file, which is
generated, when you assemble the file.

Dept.of ECE, PACEITS, Ongole 2


Microprocessors and Microcontrollers Lab Manual

LINKER
A linker is a program used to join several object files into one large object file and
convert to an exe file. The linker produces a link file, which contains the binary codes
for all the combined modules. The linker however doesn’t assign absolute addresses to
the program, it assigns is said to be relocatable because it can be put anywhere in
memory to be run. In TASM, TLINK source filename is used to link the file.
DEBUGGER
A debugger is a program which allows you to load your object code program
into system memory, execute the program and troubleshoot are debug it the debugger
allows you to look at the contents of registers and memory locations after your
program runs. It allows you to change the contents of register and memory locations
after your program runs. It allows you to change the contents of register and memory
locations and return the program. A debugger also allows you to set a break point at any
point in the program. If you inset a breakpoint the debugger will run the program upto the
instruction where the breakpoint is set and stop execution. You can then examine
register and memory contents to see whether the results are correct at that point. In
TASM, td filename is issued to debug the file.
The assembler is a program that converts an assembly input file also called source file
to an object file that can further be converted in to machine codes or an executable file
using a linker. There are a number of assemblers available like MASM, TASM and DOS
assembler.TASM is one of the popular assemblers used along with a link program to
structure the codes generated By TASM in the form of executable files.TASM reads the
source program as its input and provides an object file. The link accepts the object file
produced by TASM as input and produces an EXE file.
Before staring the process ensure that all the files namely, TASM, .EXE, LINK
.EXE, DEBUG. EXE
Are available in the same directory which is working .Start the procedure with the
following command after boot the terminal and enter the directory containing all the files
mentioned.
D: Valid directory
Cod: Change the directory with all files
Edit: Edit the assembler to enter the program
Save the files with. .ASM.
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 1234H

Dept.of ECE, PACEITS, Ongole 3


Microprocessors and Microcontrollers Lab Manual

OPR DW 0002H
RESULT DW 01H DUP ?
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
MOV BX, OPR2
CLC
ADD AX, BX
MOV DI, OFFSET RESULT
MOV DI, AX
MOV AH, 4CH
INT 03H
CODE ENDS.
END START.
The main task of any assembler program is to accept the text _assembly language
program file as input and prepare an object file .the TASM accepts the file names only with
the extension .ASM.
The TASM linking program LINK.EXE .links the different object modules of a
source program and function library routines to generate an integrated executable code of
the source program. The main input to the linker is the .OBJ file that contains the object
modules of the source program.
Debug .Exe facilitates the debugging and trouble shooting of assembly language
program. The debug utility enables to have the control these resources unto some extent.
TASM file name. ASM
TLINK file name
Debug file name.exe
G- Execute current CS: IP.
- Execute from offset in the current series
U- Un assemble from the current CS: IP
- Un assemble from the address SEG: OFFSET
D- Display 128 memory locations of RAM starting from the current display pointer
-Display memory contents SEG from offset1 to offset2

Dept.of ECE, PACEITS, Ongole 4


Microprocessors and Microcontrollers Lab Manual

ASSEMBLER DIRECTIVES:

An Assembler is a program used to convert an assembly language program in to


equivalent machine code modules which may further be converted in to executable codes.
The assembler decides the address of each label and substitutes the values for each of the
constants and variables. It then forms the machine code for the mnemonics and data in
assembly language program. While doing all these all these things, the assembler may find
out Syntax errors. The logical errors or other programming errors are not find out by the
assembler. For completing all these tasks, an assembler needs some hints from the
programmer, i.e. the required storage for a particular constant or variable, logical names of
the segments, types of the different routines and modules, end of file etc. These types of
hints are given to assembler using some predefined alphabetical strings called
“ASSEMBLER DIRECTIVES”.

DB:
This is used to reserve byte or bytes of memory locations in the available memory.
While preparing the EXE file, this directive directs the assembler to allocate the specified
number of memory bytes to the said data type that may be constant, variable or stringent.
DW:
This directive serves the same purposes as the DB directive, but it now makes the
assembler Reserve the number of memory words instead of bytes.

DQ:
This directive is used to direct the assembler to reserve words of memory for the
specified variable and may initialize it with the specified values.

ASSUME:
The ASSUME directive is used to inform the assemble, the names of the logical
segments to be assumed for different segments used in the program.

END:
The END directive marks the end of an assembly language program. When the
assembler comes across this directive, it ignores the source lines available later on.

ENDP:
In assembly language programming, the subroutines are called procedures. Thus,
procedures may be Independent program modules which return particular results or values
to the calling programs. The ENDP Directive is used to indicate an end of procedures. A

Dept.of ECE, PACEITS, Ongole 5


Microprocessors and Microcontrollers Lab Manual

procedure is usually assigned a name, i.e. label. To mark The end of a particular procedure,
the name of the procedure, i.e label appear as a prefix with the directive ENDP.

ENDS:
This directive marks the end of a logical segment. The logical segments are assigned
with names Using the ASSUME directive. The names appear with the ENDS directive as
prefixes to mark the end of Those particular segments.

LABEL:
This is used to assign a name to the current content of the location counter. At the
start of the assembly process, the assembler initializes a location counter to keep track of
memory Locations assigned to the program. As the program assembly proceeds, the
contents of the Location counter are updated.

LENGTH:
This is used to refer the length of a data array or string.

OFFSET:
When the assembler comes across the offset operator along with a label, it first
computes the 6-bit Displacement of the particular label, and replaces the string ‘offset label’
by the computed displacement.

SEGMENT:
This marks the staring of a logical segment .The started segment is also assigned a name
i.e., label by this statement. The SEGMENT and ENDS directive must bracket each logical
Segment of a program.

Dept.of ECE, PACEITS, Ongole 6


Microprocessors and Microcontrollers Lab Manual

PROCEDURE:
A common procedure for all the ALP’s(Assembly Language Prograsms) to execute
programs in TASM.
PROCEDURE FOR ENTER INTO THE TASM:-
1. Click on START menu.

2. Select and Click on RUN/Ctrl+R and type CMD then click on OK.

Dept.of ECE, PACEITS, Ongole 7


Microprocessors and Microcontrollers Lab Manual

3. Choose the TASM drive which is placed.

Exp:- Supose TASM is in DRIVE ‘D’.


First step type:- D: then click on Enter.
Then In the window appears as D:\>

Second step type:- CD space TASM then click on Enter.


Then In the window appears as D:tasm\>

Dept.of ECE, PACEITS, Ongole 8


Microprocessors and Microcontrollers Lab Manual

4. Type edit and click on Enter.

Then we will get program window. Then after Press Alt+Enter for maximising the
Window.

Dept.of ECE, PACEITS, Ongole 9


Microprocessors and Microcontrollers Lab Manual

PROCEDURE FOR EXECUTING THE ALP’S USING TASM:-

1. Click on File menu choose save option for giving the name for the Program, and the
name should be having the extenstion .asm.

2. Then type the Program for execution, Then save the Program once againe.

Dept.of ECE, PACEITS, Ongole 10


Microprocessors and Microcontrollers Lab Manual

3. Exicution:-
Step 1:- Goto file menu click on Exit.

Then In the window appears as D:tasm\>

Step 2:- Type tasm Space Program Name including .asm Then click on Enter. It
will display Errors and Warnings if any. Then correct the errors and then Repeat the Step 2
untill getting errors as None.

Finally Then In the window appears as D:tasm\>

Dept.of ECE, PACEITS, Ongole 11


Microprocessors and Microcontrollers Lab Manual

4. Type tlink space Program Name. Obj then click on Enter. Then againe the window
appears as D:tasm\>

5. Type td Space Program Name.exe then click on Enter. Then we will get the output
window, and click on OK.

Dept.of ECE, PACEITS, Ongole 12


Microprocessors and Microcontrollers Lab Manual

6. To RUN the Program press F9. To compile the Program line by line keep on press up to
INT 03H F8.

7. To observe the Result, Goto the view menu click on DUMP for note down the input
and output of the Program.

Dept.of ECE, PACEITS, Ongole 13


Microprocessors and Microcontrollers Lab Manual

8. Finally to Exit from output window Goto File menu click on Quit/Alt+X.

Dept.of ECE, PACEITS, Ongole 14


Microprocessors and Microcontrollers Lab Manual

PROCEDURE FOR EXECUTING THE ALP’S (DOS/BIOS)USING TASM:-

1. The Procedure For these Prograsms is same up to 4th point in the PROCEDURE FOR
EXECUTING THE ALP’S USING TASM.

2. Type debug Space Program Name.exe then click on Enter. Then type g click button
Enter.

3. Then final output will prasent on dos window itself.

4. To Exit from dos winow type q then click onbutton Enter.

Dept.of ECE, PACEITS, Ongole 15


Microprocessors and Microcontrollers Lab Manual

PART-II
PROCEDURE FOR INSTALLING THE ESA DRIVERS FOR INTERFACING
PROGRAMS:-

1. To run the Interfacing programs first we have to instal the ESA drivers 86E and 51E
related to 8086 Microprocessor and 8051 Microcontroller respectively.
2. The Installation of ESA drivers has to do at the first time only.
3. The process of intallation is chose the win 86E and win 51E folders and in that we can
identify the setup for the ESA Drivers related to 86E and 51E then doubbel click on stetup
then intallation process is begins.
Step 1:-doubble click on setup file then the fallowing window display.

Step 2:- It will ask for windows drivers for ESA 86/88E or 51ETrainer setup, then click on
ok button.

Dept.of ECE, PACEITS, Ongole 16


Microprocessors and Microcontrollers Lab Manual

Step 3:-Then It will ask for Begin the intallationby clicking the bellow button indicated by
Red line. Then click on the button .

Step 4:-Then againe one more window will apperas then click on continue button.

Dept.of ECE, PACEITS, Ongole 17


Microprocessors and Microcontrollers Lab Manual

Step 5:-Then final window appears as windows drivers for ESA 86/88E or 51ETrainer
setup compleated successfully. Then clik on ok button to run the interfacing programs.

Dept.of ECE, PACEITS, Ongole 18


Microprocessors and Microcontrollers Lab Manual

PROCEDURE FOR EXECUTING THE INTERFACING PROGRAMS:-

1. There is a common procedure fo r executing the interfacing the programs. First identify the
different types of trainer kits required for the execution of particular program.
2. The next process is load the program into the trainer kit.
3. The procedure for the loading the program into the trainer kit.
Step 1:- clik on start button.then goto the programs ot identify the whter ESA Drivers
loadded into the PC.

Step 2:- Then clik on the Win86E/Win51E related to the program. Then the fallowing
window will display.

Dept.of ECE, PACEITS, Ongole 19


Microprocessors and Microcontrollers Lab Manual

Step 3:- Then one more window is dispalyed to setup the communication prot to
interfaceing trainer kit. Then click on Yes button. Then the fallowing window will be
diaplayed.

Step 4:- Then we have to provide a com Port number.and click on OK button.
 The identification of COM PORT Number is very easy while we interfac kit is
connected to the PC, after switch on the kit.We have to fallow the procedure to
identify the COM PORT.
Right click on Mycomputer→ Then click on properties→ Then click on
hardware→ Click on Devise manager→ Then one more window will appear in
that click on “PLUS” Symbol befor the prot→ Then wecan idetify the serial
communication port (COM X) X-indicates the number.

Dept.of ECE, PACEITS, Ongole 20


Microprocessors and Microcontrollers Lab Manual

Step 5:- Then Win86E/Win 51E window will appear.

Step 6:- Then click on dwonload button,then the fallowing window will appear.

Step 7:- Then click on Browse button to dum the .HEX file into the Trainer kit and then
click on OK button,then the fallowing window will appear(wher you are stored the .HEX
files related to your program).Select the file and clck on Open.

Dept.of ECE, PACEITS, Ongole 21


Microprocessors and Microcontrollers Lab Manual

Step 8:- Then the fallowing window will appear.

Step 9:- Will it is downloading you have ot identify the underlined address Then the
fallowing window will appear, and click on command window.

Step 10:-Then the fallowing window will appear, then in that window you have to type g
space identified starting address.like 2000 or 8000.

EXP: > g 2000 enter then optut will be appear on the oppropriate kit or in command
window itself.

Dept.of ECE, PACEITS, Ongole 22


Microprocessors and Microcontrollers Lab Manual

1. Arithmetic operation- Multi byte Addition and Subtraction


AIM: To perfom Arithmetic operation- Multi byte Addition and Subtraction.

APPARATUS:

S. No APPARATUS Version
1. PC load with Assembler TASM Turbo Assembler 4.1

Program:-(multibyte addition):-
data segment
value1 db 10h,20h,30h,40h
value2 db 20h,30h,40h,50h
result db ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ah,00h
mov si,offset value1
mov di,offset value2
mov bx,offset result
mov cl,04h
l1:
mov al,[si]
add al,[di]
mov [bx],al
inc si
inc di
inc bx
dec cl
jnz l1
int 03h
code ends
end start
OUTPUT:-

Dept.of ECE, PACEITS, Ongole 23


Microprocessors and Microcontrollers Lab Manual

Program:-(multibyte subtraction):-

data segment
value1 db 10h,20h,30h,40h
value2 db 20h,30h,40h,50h
result db ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ah,00h
mov si,offset value1
mov di,offset value2
mov bx,offset result
mov cl,04h
l1:
mov al,[si]
sub al,[di]
mov [bx],al
inc si
inc di
inc bx
dec cl
jnz l1
int 03h
code ends
end start

OUTPUT:-

Dept.of ECE, PACEITS, Ongole 24


Microprocessors and Microcontrollers Lab Manual

2. Arithmetic operation- Multi byte Multiplication and Division

AIM: To perfom Arithmetic operation- Multi byte Multiplication and Division


APPARATUS:
S. No APPARATUS Version
1. PC load with Assembler TASM Turbo Assembler 4.1

Program:-(multibyte multiplication):-
data segment
value1 db 10h,20h,30h,40h
value2 db 20h,30h,40h,50h
result db ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ah,00h
mov si,offset value1
mov di,offset value2
mov bx,offset result
mov cl,04h
l1:
mov al,[si]
mul byte ptr[di]
mov [bx],ax
inc si
inc di
inc bx
inc bx
dec cl
jnz l1
int 03h
code ends
end start
OUTPUT:-

Dept.of ECE, PACEITS, Ongole 25


Microprocessors and Microcontrollers Lab Manual

Program:-( multibyte division):-

data segment
value1 db 20h,30h,40h,50h
value2 db 10h,20h,30h,40h
result db ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ah,00h
mov si,offset value1
mov di,offset value2
mov bx,offset result
mov cl,04h
l1:
mov al,[si]
mov ah,00h
div byte ptr[di]
mov [bx],ax
inc si
inc di
inc bx
inc bx
dec cl
jnz l1
int 03h
code ends
end start

OUTPUT:-

Dept.of ECE, PACEITS, Ongole 26


Microprocessors and Microcontrollers Lab Manual

3. Addition of n- BCD number.


AIM:
To perform the addition of n-BCD numbers.
APPARATUS:
S. No APPARATUS Version
1. PC load with Assembler TASM Turbo Assembler 4.1

Program:
data segment
opr1 equ 92h
opr2 equ 52h
result db 02 dup(00)
data ends
assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov bl,opr1
xor al,al
mov al,opr2
add al,bl
daa
mov result,al
jnc msb0
inc [result+1]
msb0:mov ah,4ch
int 21h
code ends
end start

OUTPUT:-

Dept.of ECE, PACEITS, Ongole 27


Microprocessors and Microcontrollers Lab Manual

4. Sorting
AIM:
To perfom sorting of a string using assembly language programming.
APPARATUS:
S. No APPARATUS Version
1. PC load with Assembler TASM Turbo Assembler 4.1

Program:-( ascending order of a string):-


data segment
string1 db "tasm"
result db ?
data ends
code segment
assume cs:code,ds:data,es:data
start:
mov ax,data
mov ds,ax
mov es,ax
mov dx,03h
l3:
mov cx,dx
mov si,offset string1
l2:
mov al,[si]
cmp al,[si+1]
jl l1
xchg [si+1],al
xchg [si],al
l1:
inc si
loop l2
dec dx
jnz l3
int 03h
code ends
end start
OUTPUT:-

Dept.of ECE, PACEITS, Ongole 28


Microprocessors and Microcontrollers Lab Manual

Program:-( descending order of a string):-

data segment
string1 db "tasm"
result db ?
data ends
code segment
assume cs:code,ds:data,es:data
start:
mov ax,data
mov ds,ax
mov es,ax
mov dx,03h
l3:
mov cx,dx
mov si,offset string1
l2:
mov al,[si]
cmp al,[si+1]
jg l1
xchg [si+1],al
xchg [si],al
l1:
inc si
loop l2
dec dx
jnz l3
int 03h
code ends
end start

OUTPUT:-

Dept.of ECE, PACEITS, Ongole 29

You might also like