Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 59

Microprocessors and Microcontrollers Lab Lab Manual

1. Introduction to MASM /TASM


MASM: (Microsoft assembler)
To Create Source File: An editor is a program which allows you to create a file containing the
assembly language statements for your program. This file is called a source file.
Command to create a source file

D:\MASM\ Edit filename. asm

The next step is to process the source file with an assembler. When you run the
assembler, it reads the source file of your program. On the first pass through the source program,
the assembler determines the displacement of named data items, the offset labels, etc. and puts
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 offsets, etc. that it calculated during
first pass.

D:\MASM\ Masm filename. asm Three files are generated here

With this command assembler generates three files.


• 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 the assembler list file and is
given the extension .LST. The list file contains your assembly language
statements, the binary codes for each instruction and the offset for each
instruction.
• The third file generated by this assembler is called the cross-reference file and is
given the extension .CRF. The cross-reference file lists all labels and pertinent
information required for cross – referencing

NOTE : The Assembler only finds syntax errors : It will not tell you whether program
does what it is supposed to do. To determine whether your program works, you have to
run the program and test it.

K Naveen Kumar, Asst.Prof 1


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Next step is to process the object file with linker.

D:\MASM\LINK filename . obj

Run File [ Filename1.exe] : “filename1.exe”


List file [ nul.map] : NUL
Libraries [.lib] : library_name
Definitions File [ nul.def] :

Creation of Library: Refer Modular Programming Section


A Linker is a program used to join several object files into one layer object file

NOTE: On IBM PC – type Computers, You must run the LINK program on your .OBJ
file even if it contains only one assembly module.
The linker produces a link file with the .EXE extension (an execution file)

Next Run D:\MASM\Debug filename.exe

Assembly Language Program Format :


The Assembler uses two basic formats for developing S/W
a) One method uses MODELS and
b) Other uses Full-Segment Definitions

The models are easier to use for simple tasks.


The full – segment definitions offer better control over the assembly language
task and are recommended for complex programs.
a) Format using Models:
; ABSTRACT ; 8086 program
; Aim of Program
; REGISTERS ; Registers used in your program
; PORTS ; PORTS used in your program
. MODEL (type of model i.e. size of memory system)

K Naveen Kumar, Asst.Prof 2


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

FOR EXAMPLE

. MODEL SMALL
. STACK size of stack ; define stack
. DATA ; define data segment

------Define variables

. CODE ; define code segment


HERE : MOV AX, @DATA ; load ES,DS
MOV ES, AX
MOV DS, AX

. EXIT 0 ; exit to DOS


END HERE

(or)

We can write Code segment as follows.


. CODE ; Define Code Segment
. STARTUP

. EXIT 0
END

K Naveen Kumar, Asst.Prof 3


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

MEMORY MODELS FOR THE ASSEMBLER

Model Type Description


TINY All data and code must fit into one segment. Tiny programs are
written in .COM format, which means that the program must be
originated at location 100H
SMALL This model contains two segments: one data segment of 64K bytes
and one code segment of 64K bytes.
MEDIUM This model contains one data segment of 64K bytes and any
number of code segments for large programs.
COMPACT One code segment contains the program, and any number of data
segments contains the data.
LARGE The large model allows any number of code and data segments.
HUGE This model is the same as large, but the data segments may contain
more than 64K bytes each.
FLAT Only available to MASM 6.X. The flat model uses one segment of
512K bytes to tore all data and code. Note that this model is mainly
used with Windows NT

INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING:


LEVELS OF PROGRAMMING:
There are three levels of programming
1. Machine language
2. Assembler language
3. High level language

Machine language programs are programs that the computer can understand and execute
directly. Assembly language instructions match machine language instructions, but are written
using character strings so that they are more easily understood. and High-level language
instructions are much closer to the English language and are structured.

K Naveen Kumar, Asst.Prof 4


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Ultimately, an assembly language or high level language program must be converted into
machine language by programs called translators. If the program being translated is in assembly
language, the translator is referred to as an assembler, and if it is in a high level language the
translator is referred to as a compiler or interpreter.

ASSEMBLY LANGUAGE PROGRAM DEVELOPMENT TOOLS:

EDITOR: An editor is a program, which allows you to create a file containing the assembly
language statements for your program.
ASSEMBLER: An assembler program is used to translate the assembly language Mnemonic
instructions to the corresponding binary codes. The second file generated by assembler is called
the assembler List file.
LINKER: A Linker is a program used to join several object files in to one large object file. The
linkers produce link files with the .EXE extension.
DEBUGGER: If your program requires no external hardware, then you can use a debugger to
run and debug your program. 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.

ASSEMBLER DIRECTIVES:
An assembler is a program used to convert an assembly language program into the
equivalent machine code modules. 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
mnemonics and data in assembly language program.

Assembler directives help the assembler to correctly understand assembly language


programs to prepare the codes. Commonly used assembler directives are DB, DD, DW, DUP,
ASSUME, BYTE, SEGMENT, MACRO, PROC, OFFSET, NEAR, FAR, EQU, STRUC, PTR,
END, ENDM, ENDP etc. Some directives generate and store information in the memory, while
others do not.

DB :- Define byte directive stores bytes of data in memory.


BYTE PTR :- This directive indicates the size of data referenced by pointer.

K Naveen Kumar, Asst.Prof 5


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

SEGMENT :- This directive is to indicate the start of the segment.


DUP (Duplicate) :- The DUP directive reserves memory locations given by the
number preceding it, but stores no specific values in any of
these locations.
ASSUME : - The ASSUME statement is only used with full segment
definitions. This statement tells the assembler what names
have been chosen for the code, data, extra and stack segments.
EQU : - The equate directive equates a numeric ASCII or label to
another label.
ORG : - The ORG (origin) statement changes the starting offset address
in a segment.
PROC and ENDP : - The PROC and ENDP directives indicate start and end of a
procedure (Sub routine). Both the PROC and ENDP
directives require a label to indicate the name of the procedure.
The PROC directive, must also be followed with the NEAR or
FAR. A NEAR procedure is one that resides in the same code
segment as the program. A FAR procedure may reside at any
location in the memory system.

A macro is a group of instructions that performs one task, just as a procedure. The
difference is that a procedure is accessed via a CALL instruction, while a macro is inserted in the
program at the point of usage as a new sequence of instructions.

MACRO : - The first statement of a macro is the MACRO directive preceded


with name of the macro.
ENDM : - The last statement of a macro is the ENDM instruction. Never
place a label in front of the ENDM statement.
PUBLIC &EXTRN : - The public and extern directives are very important to modular
programming. We use PUBLIC to declare that labels of code,
data or entire segments are available to other program modules.
We use EXTRN to declare that labels are external to a module.
Without this statement, we could not link modules together to

K Naveen Kumar, Asst.Prof 6


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

create a program using modular programming techniques.


OFFSET : - Offset of a label. When the assembler comes across the OFFSET
operator along with a label, it first computes the 16 – bit
displacement of the particular label, and replaces the string
‘OFFSET LABEL’ by the computed displacement.
LENGTH : - Byte length of the label. This directive is used to refer to the
length of data array or a string.

2. MICROPROCESSOR TRAINER KIT

The microprocessor trainer kit (microprocessor development kit) is an aid to understand


the architecture, interfacing and programming of a microprocessor. Here we describe the ESA
86/88 – 2-trainer kit.
ESA 86/88-2 is a powerful, general-purpose microcomputer system, which can be
operated either with 8086 CPU or with 8088 CPU. The basic system can be easily expanded
through the system BUS connector. The built in Assembler/ Disassembler feature simplifies the
programmers task of entering Assembly language programs .The on-board provision for 8087
numeric data processor makes it useful for number crunching applications. On board battery
back up provision is an added feature to take care of frequent power failures while conducting
experiments of the trainer using manually assembled code.

It is also provided with peripherals and controllers such as


8251A: Programmable communication Interface for serial communication.
8253-5: Programmable Interval Timer
8255A: Two Programmable Peripheral Interface Devices provide 48 programmable I/O lines
8259A: Programmable Interrupt Controller provides interrupt vectors for 8 sources.
8288: Bus Controller for generating control signals
ESA 86/88-2 is operated from the CRT terminals or a host computer system via the serial
monitor and also can be operated from the on board key board.

K Naveen Kumar, Asst.Prof 7


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

8255 operational modes


8255 ports can be initialized in three different modes.

MODE 0 : In this mode, all ports function as simple I/O ports without hand shaking.
MODE 1 : This mode is handshake mode where by port A and port B use the bits
Port C as handshake signals.
MODE 2 : Only port A can be initialized in mode 2. In this mode port A can be used for
Bidirectional handshake data transfer. Port B can be initialized in mode 0 or
mode1.

K Naveen Kumar, Asst.Prof 8


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

COMMUNICATION WITH A HOST COMPUTER SYSTEM

ESA 86/88-2 operating in the serial mode can be connected to either CRT terminal or
host computer system. When computer system is the controlling element it must be executing the
driver software to communicate with ESA 86/88-2.
XT86 is a package which allows the user to establish a communication link between ESA
86/88-2 system and a computer system. The link is established between asynchronous serial
ports of the computer and ESA 86/88-2.A suitable RS232-C cables have to be used for
connecting the kit to the computer system.
User can develop assembly language programs on the computer system, cross- assemble
them using a suitable cross assembler to generate object code files and then use XT86 to
download these object code files into the trainer kit for execution. User can terminate XT86 and
return control to DOS by typing Alt + X. XT86 also allows uploading of data from the memory
of the kit to the computer. The data so uploaded is same in a disk file.

INTEL 8086 MPU PROGRAMMING

USING DEBUG TO EXECUTE 80X86 PROGRAMS:

DEBUG is a utility program that allows a user to load an 80x 86 programs in to memory
and execute it step by step. DEBUG displays the contents of all processor registers after each
instruction executes, allowing user to determine if the code is performing the desired task.
DEBUG only displays the 16-bit portion of the general purpose registers. Code view is capable
of displaying the entire 32 bits. DEBUG is a very useful debugging tool. We will use DEBUG to
step through number of simple programs, gaining familiarity with DEBUG commands as we do.
DEBUG contains commands that can display and modify memory, assemble instructions,
disassemble code already placed into memory, trace through single or multiple instructions, load
registers with data, and do much more.
DEBUG loads into memory like any other program, in the fist available slot. The
memory space used by DEBUG for the user program begins after the end of DEBUG code. If an
.EXE or. COM file were specified, DEBUG would load the program according to the accepted
conventions.

K Naveen Kumar, Asst.Prof 9


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

To execute the program file PROG.EXE use this command:

D:\MASM\DEBUG PROG.EXE

DEBUG uses a minus as its command prompt, so you should see a “-”appear on display.
To get a list of some commands available with DEBUG is:
• T trace (step by step execution)
• U un assemble
• D Dump
• G go (complete execution)
• H Hex

E.g.: to execute the program file PROG.ASM use the following procedure:

MASM PROG.ASM
LINK PROG.OBJ
DEBUG PROG.EXE

K Naveen Kumar, Asst.Prof 10


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 01

Aim: Write and execute an Assemble Language Program using 8086 processor to find the
16 bit Arithmetic Operation.

Software used: MASM

Program:

a) 16 Bit Addition
Label Program
.model small
.code
mov ax,1234h
mov bx,5678h
add ax,bx
int 03h
end
1234h
5678h
68a c
-------------
b) 16 Bit Subtraction

Label Program

.model small
.code
mov ax,abcdh
mov bx,5678h
sub ax,bx
int 03h
end

K Naveen Kumar, Asst.Prof 11


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

c) 16 Bit Multiplication

Label Program
.model small
.code
mov ax,4123h

mov bx,1234h

mul bx-ax*bx
int 03h
end

d) 16 Bit Division

Label Program
.model small
.code
mov ax,7894h

mov bl,0abh
Div blax/bl
int 03h
end

Result: The 16- bit Arithmetic Operations has been performed.

K Naveen Kumar, Asst.Prof 12


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Different methods:

a) 16 Bit Addition
Label Program

.model small
.code
mov si,2500h
mov ax,[si]
mov bx,[si+2]
add ax,bx
int 03h
end
Ax=3412
Bx=cdab

b) 16 Bit Subtraction

Label Program

.model small
.code
mov si,2500h
mov ax,[si]
mov bx,[si+2]
sub ax,bx
int 03h
end

AX=1234h

BX=5678h

K Naveen Kumar, Asst.Prof 13


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

c) 16 Bit Multiplication

Label Program
.model small
.code
mov si,2500h
mov ax,[si]
mov bx,[si+2]
mul bx
int 03h
end

d) 16 Bit Division

Label Program
.model small
.code
mov si,2500h
mov ax,[si]

mov dx,[si+2]

mov bx,[si+4]
Div bx
int 03h
end
AX=1234h
DX=5678h
K Naveen Kumar, Asst.Prof 14
ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual
BX=ABCDh

Result: The 16- bit Arithmetic Operations has been performed.

K Naveen Kumar, Asst.Prof 15


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 02

Aim: Write and execute an Assemble Language Program using 8086 processor to sort the
8-bit numbers in Ascending order.

Software used: MASM

Program:
Label Program 2504 12h/ff
.model small 2503 Abh/ff/12/ab
2502 01h/ff/ab/89
.code
2501 89h/ff/01/12
mov ch, 04h 2500 Ffh/89/01
back1: mov si,2500h
N=inputs=5
mov cl,04h Counter=N-1=comparisons=cl=4/3/2/1/0
back: mov al,[si] Iterations counter=N-1=ch=4/1

cmp al,[si+1]
jc nxt jnc
xchg al,[si+1]
xchg al,[si]
nxt: inc si
dec cl
jnz back
dec ch
jnz back1
int 03h
end

Result: The sorting of 8-bit ascending order is performed for a given set of numbers.

K Naveen Kumar, Asst.Prof 16


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 03

Aim: Write and execute an Assemble Language Program using 8086 processor to sort the
8-bit numbers in Descending order.

Software used: MASM

Program:

Label Program
.model small
.code
mov ch, 04h
back1: mov si,2500h
mov cl,04h
back: mov al,[si]
cmp al,[si+1]
jnc nxt
xchg al,[si+1]
xchg al,[si]
nxt: inc si
dec cl
jnz back
dec ch
jnz back1
int 03h
end

Result: The sorting of 8-bit descending order is performed for a given set of numbers.

K Naveen Kumar, Asst.Prof 17


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 04

Aim: Write and execute an Assemble Language Program using 8086 processor to sort the
16-bit numbers in Ascending order.

Software used: MASM

Program:

Label Program
.model small
.code
mov ch,04h
back1: mov si,2500h
mov cl,04h
back: mov ax,[si]
cmp ax,[si+2]
jc nxt
xchg ax,[si+2]
xchg ax,[si]
nxt: inc si
inc si
dec cl
jnz back
dec ch
jnz back1
int 03h
end

Result: The sorting of 16-bit ascending order is performed for a given set of numbers.

K Naveen Kumar, Asst.Prof 18


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 05

Aim: Write and execute an Assemble Language Program using 8086 processor to sort the
16-bit numbers in Descending order.

Software used: MASM

Program:

Label Program
.model small
.code
mov ch,04h
back1: mov si,2500h
mov cl,04h
back: mov ax,[si]
cmp ax,[si+2]
jnc nxt
xchg ax,[si+2]
xchg ax,[si]
nxt: inc si
dec cl
jnz back
dec ch
jnz back1
int 03h
end

Result: The sorting of 16 bit descending order is performed for a given set of numbers.

K Naveen Kumar, Asst.Prof 19


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 06

Aim: Write and execute an Assemble Language Program using 8086 processor to find the
Largest number from a given string.

Software used: MASM

Program:

Label Program
.model small
.code
mov ch,04h
mov si,2000h
back: mov ax,[si]
cmp ax,[si+2]
jc nxt
xchg ax,[si+2]
xchg ax,[si]
nxt: inc si
inc si
dec ch
jnz back
int 03h
end

Result: The Largest Numbers is been found from a given set of numbers.

K Naveen Kumar, Asst.Prof 20


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 07

Aim: Write and execute an Assemble Language Program using 8086 processor to find the
Smallest number from a given string.

Software used: MASM

Program:

Label Program
.model small
.code
mov ch,04h
mov si,2000h
back: mov ax,[si]
cmp ax,[si+2]
jnc nxt
xchg ax,[si+2]
xchg ax,[si]
nxt: inc si
inc si
dec ch
jnz back
int 03h
end

Result: The Smallest Numbers is been found from a given set of numbers.

K Naveen Kumar, Asst.Prof 21


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 08

Aim: Write and execute an Assemble Language Program using 8086 processor to
separate the given numbers and into even and odd numbers and store the result in two
different locations.

Software used: MASM

Program:

Label Program
.model small
.code
mov cx,000ah
mov si,1000h
mov di,1010h
mov bx,1020h
back: mov al,[si]
mov ah,al
rcr al,01
jc odd1
mov [di],ah
inc di
jmp xyz
odd1: mov [bx],ah
inc bx
xyz: inc si
loop back
int 03h
end

Result: The Sorting and Separation of Even and Odd numbers had been performed.

K Naveen Kumar, Asst.Prof 22


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 09

Aim: Write and execute an Assemble Language Program using 8086 processor to
separate the given numbers and into positive and negative numbers and store the result in
two different locations.

Software used: MASM

Program:

Label Program
.model small
.code
mov cx,0ah
mov si,1000h
mov di,1010h
mov bx,1020h
back: mov al,[si]
mov ah,al
rcl al,01
jc neg1
mov [di],ah
inc di
jmp xyz
neg1: mov [bx],ah
inc bx
xyz: xyz:inc si
loop back
int 03h
end

Result: The Sorting and Separation of Positive and Negative numbers had been performed.

K Naveen Kumar, Asst.Prof 23


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 10

Aim: Write and execute an Assemble Language Program using 8086 processor to find the
Length of the given String

Software used: MASM

Program:

Label Program
.model small
.data
str db "Microprocessor",0
.code
mov ax,@data
mov ds,ax
mov si,offset str
xor cx,cx
back: mov al,[si]
cmp al,00h
jz xx
inc cx
inc si
jmp back
xx: int 03h
end

Result: The length of a given String has been calculated.

K Naveen Kumar, Asst.Prof 24


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 11

Aim: Write and execute an Assemble Language Program using 8086 processor to read a
string from Keyboard and insert in between a given string.

Software used: MASM

Program:

Label Program
assume cs:code, ds:data
data segment
org 0020h
stg db"nmr college",00h
org 0040h
rst db 25h dup(00)
data ends
code segment
start: mov ax,data
mov ds,ax
mov si,offset stg
mov di,offset rst
mov cx,04h
back: mov al,[si]
mov [di],al
inc si
inc di
loop back
again: mov ah,01h

K Naveen Kumar, Asst.Prof 25


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

int 21h
cmp al,'$'
jz next
mov [di],al
inc di
jmp again
next: mov al,[si]
cmp al,00h
jz xx
mov [di],al
inc si
inc di jmp
next int
xx: 03h code
ends
end start

Result: The ALP to insert a string is written and performed.

K Naveen Kumar, Asst.Prof 26


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 12

Aim: Write and execute an Assemble Language Program using 8086 processor to Delete
the string from the string given.

Software used: MASM

Program:

Label Program
assume cs:code,ds:data
data segment
org 0020h
stg db"nmr engg
college",00h
org 0040h
rst db 25h dup(00)
data ends
code segment
start: mov ax,data
mov ds,ax
mov si,offset stg
mov di,offset rst
mov cx,04h
back: mov al,[si]
mov [di],al
inc si
inc di
loop back

K Naveen Kumar, Asst.Prof 27


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

next: mov al,[si+5]


cmp al,00h
jz xx
mov [di],al
inc si
inc di jmp
next int
xx: 03h code
ends
end start

Result: The ALP to delete a string is written and performed.

K Naveen Kumar, Asst.Prof 28


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 13

Aim: Write and execute an Assemble Language Program using 8086 processor to find
whether a given number is Prime or Not

Software used: MASM

Program:

Label Program
.model small
.data
Org 2000h
str1 db "prime",0
str2 db "not prime",0
Org 0000h
rst db 0ah
.code
mov ax,@data
mov ds,ax
mov al,09h
mov bl,al
mov cl,al
back: dec bl
cmp bl,01h
jz next
mov ah,00h
mov al,cl
div bl

K Naveen Kumar, Asst.Prof 29


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

cmp ah,00h
jz again
jmp back
again: mov si,offset str2
mov di,offset rst
jmp back1
next: mov si,offset str1
mov di,offset rst
back1: mov al,[si]
mov [di],al
cmp al,00h
jz xx
inc si
inc di
jmp back1
xx: int 03h
end

Result: The given number is examined through ALP and is displayed whether the given number
is a Prime or Not.

K Naveen Kumar, Asst.Prof 30


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 14

Aim: Write and execute an Assemble Language Program using 8086 processor to find the
Sum of ‘n’ natural numbers.

Software used: MASM

Program:

Label Program
.model small
.code
xor bx, bx
mov dh, 05h
mov si, 2000h
bak: mov al, [si]
mov ah, 00h
adc al, bl
inc bl
inc si
dec dh
jne bak
int 03h
end

Result: The Sum of ‘n’ natural numbers is performed.

K Naveen Kumar, Asst.Prof 31


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 15

Aim: Write and execute an Assemble Language Program using 8086 processor to find the
Average of ‘n’ numbers given.

Software used: MASM

Program:

Label Program
.model small
.code
mov si, 2000h
mov cx, 05h
xor ax, ax
bak: add al, [si]
inc si
jnc next
inc ah
loop bak
next: mov [si], al
mov [si+1], ah
div bx
int 03h
end

Result: The Average of n numbers are performed.

K Naveen Kumar, Asst.Prof 32


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

INTERFACING

WITH 8086 PROCESSOR

K Naveen Kumar, Asst.Prof 33


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 16

Aim: Interface a LED trainer kit to 8086 microprocessor and write a program to display
the necessary pattern.

Software used: MASM


XT86E
EXE2HEX

Hardware Used: 1. LED Trainer Kit


2. 8086 Processor Trainer Kit
3. FRC Cable and Connecting Wire
4. Power Supply
Program:
Label Program
.model small
.code
org 2000h
mov al,80h
mov dx,0ffe6h
out dx,al
again: mov al,00h
mov dx,0ffe0h
back: out dx,al
call delay
inc al
cmp al,0ah
jnz back
back1: out dx,al
call delay
dec al

K Naveen Kumar, Asst.Prof 34


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

cmp al,00h
jnz back1
jmp again
delay: mov cx,07ffh
xx: loop xx
ret
int 03h
end

Result: The required pattern has been displayed in the LED display

K Naveen Kumar, Asst.Prof 35


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 17

Aim: Interface a Stepper Motor along with signal driver trainer kit to 8086
microprocessor and write a program to rotate the stepper motor in clock wise and anti
clock wise direction.

Software used: MASM


XT86E
EXE2HEX

Hardware Used: 1. Stepper Motor


2. Driver circuit Trainer Kit
3. 8086 Processor Trainer Kit
4. FRC Cable and Connecting Wire
5. Power Supply
Program:
Label Program
.model small
.code
org 2000h
mov al,80h
mov dx,0ffe6h
out dx,al
mov cx,600
again: mov al,88h
mov dx,0ffe0h
back: out dx,al
ror al,01
call delay
dec cx
jnz back

K Naveen Kumar, Asst.Prof 36


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

mov cx,800
mov al,88h
mov dx,0ffe0h
back1: out dx,al
rol al,01
call delay
dec cx
jnz back1
jmp again
delay: push cx
mov cx,02ffh
l1: loop l1
pop cx
ret
int 03h
end

Result: The Clock wise and Anti Clock wise rotation of the Stepper motor has been observed.

K Naveen Kumar, Asst.Prof 37


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 18

Aim: Interface a DAC trainer kit to 8086 microprocessor and write a program to display
the necessary pattern.

Software used: MASM


XT86E
EXE2HEX

Hardware Used: 1. DAC Trainer Kit


2. 8086 Processor Trainer Kit
3. FRC Cable and Connecting Wire
4. CRO and Power Supply
Program:
a) Ramp Signal
Label Program
.model small
.code
org 2000h
mov al,80h
mov dx,0ffe6h
out dx,al
rpt: mov al,00h
mov dx,0ffe0h
back: out dx,al
inc al
cmp al,0ffh
jne back
jmp rpt
int 03h
end

K Naveen Kumar, Asst.Prof 38


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

b) Triangle Signal
Label Program
.model small
.code
org 2000h
mov al,80h
mov dx,0ffe6h
out dx,al
rpt: rpt:mov al,00h
mov dx,0ffe0h
back: back:out dx,al
inc al
cmp al,0ffh jne
back back1:out
back1: dx,al dec al
cmp al,00h
jne back1
jmp rpt
int 03h
end

K Naveen Kumar, Asst.Prof 39


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

c) Saw Tooth Signal


Label Program
.model small
.code
org 2000h
mov al,80h
mov dx,0ffe6h
out dx,al
rpt: mov al,00h
mov dx,0ffe0h
back: out dx,al
call delay
add al,51
cmp al,0ffh
jne back
back1: sub al,51
out dx,al
call delay
cmp al,00h
jne back1
delay: mov cx,0ffh
l1: loop l1
ret
int 03h
end

K Naveen Kumar, Asst.Prof 40


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

d) Square Signal
Label Program
.model small
.code
org 2000h
mov al,80h
mov dx,0ffe6h
out dx,al
back: mov al,00h
mov dx,0ffe0h
out dx,al
call delay
mov al,0ffh
out dx,al
call delay
jmp back
delay: mov cx,0ffh
l1: loop l1
ret
int 03h
end

Result: The Ramp, Triangle, Square and Saw Tooth Waveforms are observed in the CRO.

K Naveen Kumar, Asst.Prof 41


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

MICROCONTROLLER

K Naveen Kumar, Asst.Prof 42


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 19

Aim: Write and execute an Assemble Language Program using 8051 micro controller for
16-bit arithmetic operations

Software used: Kiel u Vision 4

Program:

a) Addition

Label Program

Org 000h
mov a, # 0fdh
mov b, # 0a0h
add a,b
end

b) Subtraction

Label Program

Org 000h
mov a, # 0fdh
mov b, # 0a0h
sub a,b
end

K Naveen Kumar, Asst.Prof 43


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

c) Multiplication

Label Program

Org 000h
mov a, # 12h
mov b, # 030h
mul ab
end

d) Division

Label Program

Org 000h
mov a, # 20h
mov b, # 02h
div ab
end

Result: The 8-bit Arithmetic operation have been performed.

K Naveen Kumar, Asst.Prof 44


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 20

Aim: Write and execute an Assemble Language Program using 8051 micro controller for
addition of ‘n’ natural numbers.

Software used: Kiel u Vision 4

Program:

Label Program

Org 000h
mov a, # 00h
mov r0, #00h
mov r1, #10h
again: inc r0
add a, r0
DJNZ r1, again
end

Result: The Average of first n natural numbers are performed

K Naveen Kumar, Asst.Prof 45


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 21

Aim: Write and execute an Assemble Language Program using 8051 micro controller to
toggle all the bits of port1 by sending 55h and AAh continuously. Add a time delay
between each data transmission to port1.

Software used: Kiel u Vision 4

Program:

Label Program

Org 000h
again: mov a, # 055h
mov p1, a
lcall delay
cpl a
lcall delay
sjmp again

delay: org 400h


here: mov r0, #0ffh
djnz r0, here
ret
end

Result: Date transmission is done continuously to perform Toggle operation

K Naveen Kumar, Asst.Prof 46


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 22

Aim: Write and execute an Assemble Language Program using 8051 micro controller to
generate a square wave of 50% duty cycle on p1.5 by using Timer 0.

Software used: Kiel u Vision 4

Program:

Label Program

Org 000h
mov tmod, # 01h
back: mov th0, #0ffh
mov tl0, #0f2h
cpl p1.5
acall delay
sjmp back

delay: setb tr0


here: jnb tf0, here
crl tr0
clr tf0
ret
end

Result: Square wave with 50% duty cycle has been generated.

K Naveen Kumar, Asst.Prof 47


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 23

Aim: Write and execute an Assemble Language Program using 8051 micro controller to
generate a square wave of 33% duty cycle on p1.5 by using Timer 0.

Software used: Kiel u Vision 4

Program:

Label Program
Org 000h
clr p1.5
mov tmod, # 01h
back: mov th0, #0ffh
mov tl0, #0f2h
cpl p1.5
acall delay

mov th0, #0ffh


mov tl0, #0f2h
cpl p1.5
acall delay

mov th0, #0ffh


mov tl0, #0f2h
acall delay
sjmp back

delay: setb tr0

K Naveen Kumar, Asst.Prof 48


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

here: jnb tf0, here


crl tr0
clr tf0
ret
end

Result: Square wave with 50% duty cycle has been generated.

K Naveen Kumar, Asst.Prof 49


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 24

Aim: Write and execute an Assemble Language Program using 8051 micro controller to
generate a square wave with Ton = 5ms.

Software used: Kiel u Vision 4

Program:

Label Program

Org 000h
mov tmod, # 01h
back: mov th0, #0eeh
mov tl0, #00h
cpl p1.5
acall delay
sjmp back

delay: setb tr0


here: jnb tf0, here
crl tr0
clr tf0
ret
end

K Naveen Kumar, Asst.Prof 50


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Calculation:

Freq = 11.0592 MHz

Time Period = 1/ 11.0592MHz

= 1.085us

For t= 5ms; 5ms / 1.085us =4608 clocks

For loading values into TH and TL

65536 -4608 = 60928 = EE00H

Therefore TH = 0EEH and TL=00H

Result: Square wave for T= 5ms has been generated.

K Naveen Kumar, Asst.Prof 51


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 25

Aim: Write and execute an Assemble Language Program using 8051 micro controller to
generate a square wave with Ton = 3ms and Toff= 10ms

Software used: Kiel u Vision 4

Program:

Label Program
Org 000h
mov tmod, # 01h
back: mov th0, #0f5h
mov tl0, #33h
cpl p1.5
acall delay
mov th0, #0dbh
mov tl0, #ffh
cpl p1.5
acall delay
sjmp back
delay: setb tr0
here: jnb tf0, here
crl tr0
clr tf0
ret
end

Result: Square wave for Ton= 3ms, and Toff= 10ms has been generated.

K Naveen Kumar, Asst.Prof 52


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 26

Aim: Write and execute an Assemble Language Program using 8051 micro controller to
generate a square wave in mode 2.

Software used: Kiel u Vision 4

Program:

Label Program

Org 000h
mov tmod, # 20h
mov th1, #05h
setb tr1
back: jnb tf1, back
cpl p1.2
clr tf1
ret
end

Result: Square wave using mode 2 has been generated and verified.

K Naveen Kumar, Asst.Prof 53


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 27

Aim: Write and execute an Assemble Language Program using 8051 micro controller to
transfer a character ‘Y’ at 9600 baud rate continuously and also send a character ‘N’
through port 0 which is connected to a display device

Software used: Kiel u Vision 4

Program:

Label Program
Org 000h
mov tmod, # 20h
mov th1, #0fdh
mov scon, # 50h
setb tr1
clr ti
again: mov sbuf, #’Y’
here: jnb ti, here
clr ti
mov p0, #’N’
sjmp again
end

Result: Serial transmission of a character trough UART and also through port has been
performed.

K Naveen Kumar, Asst.Prof 54


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 28

Aim: Write and execute an Assemble Language Program using 8051 micro controller to
transfer a string at 9600 baud rate continuously.

Software used: Kiel u Vision 4

Program:

Label Program

Org 2000h
str: db “hello world”, 0

Org 000h
mov tmod, # 20h
mov th1, #0fdh
mov scon, # 50h
setb tr1
mov dptr, #str
back: clr a,
movc a, @a+dptr
jz last
lcall tran
sjmp back
last: sjmp $
tran: mov sub, a
jnb ti, $
clr ti

K Naveen Kumar, Asst.Prof 55


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

inc dptr
ret
end

Result: Serial transmission of a string trough UART and also through port has been performed.

K Naveen Kumar, Asst.Prof 56


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

Experiment No: 29

Aim: Write and execute an Assemble Language Program using 8051 micro controller to
interface a LCD to display necessary string.

Software used: Kiel u Vision 4


XT51E

Hardwarr used: 1. LCD Trainer Kit


2. 8051 Micro controller Trainer Kit
3. FRC Cable and Connecting Wire
4. Power Supply

Program:

Label Program
Org 8000h
mov a, #80h
mov dptr, #0e803h
movx @dptr, a
mov dptr, #8100h
again: clr a
movc a, @a+dptr
jz data1
acall cmd
acall delay
sjmp again

cmd: push dpl


push dph
mov @dptr, #0e800h

K Naveen Kumar, Asst.Prof 57


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

movx @dptr, a
mov @dptr, #0e801h
mov a, # 04h
movx @dptr, a
mov a, # 00h
movx @dptr, a
pop dph
pop dpl
inc dptr
ret

data1: inc dptr


clr a
movc a, @a+dptr
jz final
push dpl
push dph
mov @dptr, #0e800h
movx @dptr, a
mov @dptr, #0e801h
mov a, # 05h
movx @dptr, a
mov a, # 01h
movx @dptr, a
pop dph
pop dpl

K Naveen Kumar, Asst.Prof 58


ECE Dept, NMREC
Microprocessors and Microcontrollers Lab Lab Manual

acall delay
sjmp data1

final: sjmp $

delay: mov r0, #0ffh


here: djnz r0, here
ret

Org 8100h
db 30h, 30h, 30h,
38h,01h,
02h,06h,0eh,80h, 00h
db “MP&MC Lab”,00h
end

Result: The given string is displayed by interfacing LCD to 8051 micro controller.

K Naveen Kumar, Asst.Prof 59


ECE Dept, NMREC

You might also like