You are on page 1of 124

Department of Electronics and Communication Engineering

III Year / V Semester

20ECL57 – MICROPROCESSORS LAB

LAB MANUAL

Academic Year : 2020 - 2021


Semester : ODD
ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering

MICROCROPROCESSORS

Course Code : 20ECL57 Credits : 1.5


L:T:P : 0:0:1.5 CIE Marks : 25
Exam Hours : 03 SEE Marks : 25

LIST OF EXPERIMENTS

1. Write an assembly level programs for basic arithmetic operations using 8086 (i) Signed
and Unsigned Addition (ii) Subtraction (iii) Signed and Unsigned Multiplication (iv)
Signed and Unsigned Division
2. Write an assembly level programs assembly level programs for basic logical operation
using 8086 (i)To check number is positive or negative (ii)To count number of one’s &
zero’s
3. Write an assembly Level programs for code conversion of 8086
(i) ASCII to binary;
(ii) Decimal to Hex;
(iii) ASCII to Decimal;
(iv) Binary to BCD and vice versa
4. Write an assembly level programs for String operations using 8086
(i) Reverse the string , (ii)To check whether the string is palindrome or not
5. Write an assembly level programs using 8086 for sorting operations like ascending,
descending, largest and smallest in microprocessor
6. Interfacing of 8086 with (Assembly Level Programming)
i) Stepper motor
i) Seven segment Display
ii) Logic controller
(BCD up counter and Down counter)
iii)Keyboard Display Interface
7. Write a assembly level program for basic arithmetic and logical operations in
8051 microcontroller.

Department of Electronics and Communication Engineering Page 2 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

8. Assembly Level Programming to illustrate the interfacing of stepper motor,


switches, LCD & LED modules with the microcontroller 8051.

Lab In-charge HOD-ECE

Department of Electronics and Communication Engineering Page 3 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering


MICROPROCESSORS LAB
Course Code : ECE52 Credits : 1.5
L: T:P : 0:0:1.5 CIE Marks : 25
Exam Hours : 03 SEE Marks :25
Expt. Course
Topics
No Outcomes
1.Write an assembly level programs for basic arithmetic
operations using 8086 (i) Signed and Unsigned Addition
(ii) Subtraction (iii) Signed and Unsigned Multiplication
(iv) Signed and Unsigned Division CO1
1 2. Write an assembly level programs assembly level programs
for basic logical operation using 8086
(i)To check number is positive or negative
(ii)To count number of one’s & zero’s

Write an assembly Level programs for code conversion of


8086
CO2
(i)ASCII to binary;
2
(ii) Decimal to Hex;
(iii) ASCII to Decimal;
(iv) Binary to BCD and vice versa
1.Write an assembly level programs for String operations
using 8086 (i)To check whether the string is palindrome or
not. (ii) Reverse the string
CO3
3 2.Write an assembly level programs using 8086 for sorting
operations like ascending, descending, largest and smallest in
microprocessor
1.
Interfacing of 8086 with (Assembly Level Programming)
i) Stepper motor
i) Seven segment Display
4 CO4
ii) Logic controller
(BCD up counter and Down counter)
iii) Keyboard Display Interface
Write a assembly level program for basic arithmetic and logical
5 CO5
operations in 8051 microcontroller.
6 Assembly Level Programming to illustrate the interfacing of CO6

Department of Electronics and Communication Engineering Page 4 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

stepper motor, switches, LCD & LED modules with the


microcontroller 8051.

CO1 Write assembly level programs using 8086 to perform arithmetic and logical
operations.
CO2 Apply the knowledge of computer number system to write code conversion
programs in 8086.
CO3 Develop assembly code for string operations, sorting of numbers and branch
instructions of 8086.
CO4 Demonstrate the I/O interfacing of 8086 with peripheral devices.
CO5 Write 8051 assembly level programs to perform arithmetic and logical
operations.
CO6 Demonstrate the interfacing of 8051 with stepper motor, switches, LCD & LED
modules.

Department of Electronics and Communication Engineering Page 5 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

INDEX
Expt Page
Name of the Experiment
. No. NO
INTRODUCTION ABOUT 8086 MICROPROCESSOR & 8051 6-10
MICROCONTROLLER

PROGRAM INVOLVING ARITHMETIC OPERATIONS

1.1 Write an ALP to Perform Addition of two 32 bit numbers. 11-12

1.2 Write an ALP for Subtraction of two 32 bit numbers 13-14

1.3.1 Aim : Write an ALP for Multiplication of two signed 8 bit numbers. 15-16

1.3.2 Write an ALP for Multiplication of two signed 16-bit numbers. 17-18

1.3.3 Write an ALP for Multiplication of two unsigned 8 bit numbers 19-20

1.3.4 Write an ALP for Multiplication of two unsigned 16-bit numbers 21-22

1.4.1 Write an ALP for 8-bit signed division 23-24

1.4.2 Write an ALP for 16-bit signed division 25-26

1.4.3 Write an ALP for 8 -bit Unsigned division 27-28

1.4.4 Write an ALP for 16-bit Unsigned division 29-30

PROGRAM INVOLVING LOGICAL OPERATIONS

2.1 Write an ALP to check whether the given number is Positive or Negative. 31-32

33-34
2.2 Write an ALP to find the number of 1s and 0s in a given number.

2.3 Write an ALP to find the given number is 2 out of 5 code or not 35-36

2.4 Write an ALP to transfer a block of data from source to destination 37-38

PROGRAM INVOLVING CODE CONVERSION

3.1.1 Write an ALP to Convert Binary to BCD 39-40

3.1.2 Write an ALP to Convert BCD to Binary (16-bit) 41-42

3.2.1 Write an ALP for conversion of ASCII code to Binary code 45-46

3.2.2 Write an ALP for conversion of Binary code to ASCII code 47-48

PROGRAMS INVOLVING SRING OPERATIONS

4.1 Write an ALP to transfer a String from source to destination 51-52

Department of Electronics and Communication Engineering Page 6 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

4.2 Write an ALP to reverse the given string 53-54

4.3 Write an ALP to check whether the given string is Palindrome or not 55-56

5.1 Write an ALP to find the largest number in an array 57-58

5.2 Write an ALP to find the Smallest number in an array 59-60

5.3 Write an ALP to sort the given array in an Ascending order. 61-62

5.4 Write an ALP to sort the given array in an Descending order. 63-64

6.0 Write an ALP to MOVE A BLOCK OF DATA FROM SOURCE TO 65-66


DESTINATION
a)

b) Write an ALP to MOVE A BLOCK OF DATA FROM SOURCE TO 67-68


DESTINATION
c.1) Write an ALP TO arrange the series of numbers in ascending order 69-70

C.2) Write an ALP to arrange the series of numbers in descending order 71-72

7.0 Write a ALP for addition of two 16-bit numbers 73-74


a)

b) Write an ALP for subtraction of two 16-bit numbers 75-76

c) Write an ALP for multiplication / square of two 16-bit numbers 77-78

d) Write an ALP for division of 16-bit number by a 8- bit number 79-80

8.0 Write an ALP to illustrate logical & bit manipulation 81-84


Operation
9.0 Write an ALP for bcd to ascii code conversion 85-86

a)

b) Write an ALP for ascii to bcd code conversion. 87-88

c) Write an ALP for ascii to decimal code conversion 89-90

d) Write an ALP for decimal to ascii code conversion. 91-92

e) Write an ALP for hex to decimal code conversion 93-94

f) Write an ALP for decimal to hexadecimal code conversion. 95-96

10.1 Write an ALP to verify the Timer in 8051 Microcontroller 97-98

Write an ALP to illustrate the Interrupts and UART operations in 8051 99-100
10.2 Microcontroller.

11 Write an ALP program to illustrate stepper motor Control interface to 8051. 101-102

12 Write an ALP to illustrate LED interface to 8051 103-104

Department of Electronics and Communication Engineering Page 7 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

13 Write an ALP to illustrate LCD interface to 8051 105-106

14 Write an ALP to illustrate LED&switch interface 107-108

Microprocessor 8086& Microcontroller 8051 Viva Questions 110-112

Scheme of Evaluation

Evaluation Criteria Weightage

CIE – I 15 Marks

CIE – II ( 2 – Lab 10 Marks


Internals – 25 Marks
Each )

SEE 25 Marks

Prepared By Verified By Approved By

Dr.Sanjeev Sharma

HOD-ECE

Department of Electronics and Communication Engineering Page 8 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 9 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 10 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 11 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 12 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 13 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 14 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.1. Addition of two 32 bit numbers

Start

Initialize Data Segment & Code segment

Allocate memory to store result.


Initialize two 32 bit numbers.

Store DS reg. by starting address of data segment.

Clear carry & Add lower 16-bits of data 1 & 2.

Store the sum in memory

Add higher 16-bits of data 1 & 2 with carry

Store the sum & final carry in memory

Code ends end main

Department of Electronics and Communication Engineering Page 15 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1) AIM: WRITE A MICROPROCESSOR 8086 PROGRAM TO ILLUSTRATE THE


FOLLOWING BASIC ARITHMETIC OPERATIONS:

1.1.Aim : write an ALP to Perform Addition of two 32 bit numbers.

Software Required: MASM Assembler

data segment
num1 dw 1234h, 5678h
num2 dw 0ab12h, 0cdefh
result dw 3 dup(?)
data ends

code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov dx,00h
mov ax, num1
mov bx, num2
clc
add ax, bx
mov result, ax
mov ax, num1+2
mov bx, num2+2
adc ax, bx
mov result+2, ax
adc dx, 00h
mov result+4, dx
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program for addition of two 32 bit numbers is executed and the output is verified.

Input: num1: 5678 1234H num1: 1122 3344


num2: CDEF AB12H num2: 55667788

Output: 0001 2467 BD46H 0000 6688AACC

Department of Electronics and Communication Engineering Page 16 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.2. Subtraction of two 32 bit numbers.

Start

Initialize Data Segment & Code segment

Allocate memory to store result.


Initialize two 32 bit numbers.

Store DS reg. by starting address of data segment.

Clear carry & Subtract lower 16-bits of data 1 by 2.

Store the result in memory

Subtract higher 16-bits of data 1 by 2 with barrow

Store the result & final barrow in memory

Code ends end main

Department of Electronics and Communication Engineering Page 17 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.2. Write an ALP for Subtraction of two 32 bit numbers.

Software Required: MASM Assembler

data segment
n1 dw 0ba98h, 0fedch
n2 dw 5678h, 1234h
result dw 3 dup(?)
data ends

code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov dx, 00h
mov ax, n1
mov bx, n2
clc
sub ax, bx
mov result, ax
mov ax, n1+2
mov bx, n2+2
sbb ax, bx
mov result+2, ax
sbb dx, 00h
mov result+4, dx
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program for Subtraction of two 32 bit numbers is executed and the output is verified.

Input: n1: FEDC BA98H


n2:1234 5678H

Output: 0000 ECA8 6420H

Input: n1:F234 6678H


n2:F780 5384H

Output: FFFF FAB4 12F4H

1.3.1. Multiplication of two signed 8-bit numbers.

Department of Electronics and Communication Engineering Page 18 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Start

Initialize Data Segment & Code segment

Allocate memory to store result.


Initialize two signed 8 bit numbers.

Store DS reg. by starting address of data segment.

Multiply both the numbers using signed multiplication.

Store the result in memory

Code ends end main

Multiplication of two 8 bit signed numbers

Department of Electronics and Communication Engineering Page 19 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.3.1. Aim : Write an ALP for Multiplication of two signed 8 bit numbers.

Software Required : MASM Assembler

data segment
n1 db 0f4h
n2 db 12H
result dw 2dup(?)
data ends
code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov al, n1
mov bl, n2
imul bl
mov result, ax
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program for multiplication of two signed 8 bit numbers is executed and the output is verified.

Input: n1=F4H n1= D2H


n2=12H n2= 46H
Output: 1128H 396CH

Department of Electronics and Communication Engineering Page 20 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.3.2. Multiplication of two signed 16 bit numbers.

Start

Initialize Data Segment & Code segment

Allocate memory to store result.


Initialize two signed 16-bit numbers.

Store DS reg. by starting address of data segment.

Multiply both the numbers using signed multiplication.

Store the result in memory

Code ends end main

Department of Electronics and Communication Engineering Page 21 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Multiplication of two 16 bit signed numbers

1.3.2. Aim : Write an ALP for Multiplication of two signed 16-bit numbers.

Software Required : MASM Assembler

Data segment
n1 dw 1234h
n2 dw ff40h
result dw (?)
data ends
code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov ax, n1
mov bx, n2
imul bx
mov result, ax
mov result+2, dx
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program for multiplication of two signed 16 bit numbers is executed and the output is verified.

Input: n1=1234h n1= 1122 H


n2=ff40H n2= 3344H
Output: 12265900 36E5308H

Department of Electronics and Communication Engineering Page 22 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.3.3. Multiplication of two unsigned 8 bit numbers.

Start

Initialize Data Segment & Code segment

Allocate memory to store result.


Initialize two unsigned 8-bit numbers.

Store DS reg. by starting address of data segment.

Multiply both the numbers using unsigned multiplication.

Store the result in memory

Code ends end main

Department of Electronics and Communication Engineering Page 23 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.3.3. Aim: Write an ALP for Multiplication of two unsigned 8 bit numbers.

Software Required : MASM Assembler

data segment
n1 db 0ffh
n2 db 0fh
result dw ?
data ends
code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov al, n1
mov bl, n2
mul bl
mov result, ax
mov ah, 4ch
int 21h
code ends
end main
RESULT: The program for multiplication of two unsigned 8 bit numbers is executed and the output is verified.

Input: n1=0ffH n1= 12H


n2=0fH n2= 34H
Output: 0EF1H 3A8H

Department of Electronics and Communication Engineering Page 24 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.3.4 Multiplication of two unsigned 16-bit numbers.

Start

Initialize Data Segment & Code segment

Allocate memory to store result.


Initialize two unsigned 16-bit numbers.

Store DS reg. by starting address of data segment.

Multiply both the numbers using unsigned multiplication.

Store the result in memory

Code ends end main

Department of Electronics and Communication Engineering Page 25 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Multiplication of two 16 bit unsigned numbers


1.3.4 Aim : Write an ALP for Multiplication of two unsigned 16-bit numbers

Software Required : MASM Assembler

data segment
n1 dw 1234h
n2 dw 0ff40h
result dw ?, ?
data ends
code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov ax, n1
mov bx, n2
mul bx
mov result, ax
mov result+2, dx
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program for multiplication of two unsigned 16 bit numbers is executed and the output is verified.

Input: n1=1234H;n2=0FF40H; Output:12265900

N1= 1234H n2=5678H Output: 6260060

Department of Electronics and Communication Engineering Page 26 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.4.1 8-bit signed division.

Start

Initialize Data Segment & Code segment

Allocate memory to store result.


Initialize two signed 8-biit numbers.

Store DS reg. by starting address of data segment.

Convert one of the byte to word or word to double word

Divide the word by byte or double word by word using signed division

Store the result in memory

Code ends end main

Department of Electronics and Communication Engineering Page 27 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.4.1. Aim : Write an ALP for 8-bit signed division.

Software Required : MASM Assembler

8 bit signed division


data segment
n1 db 0afh Input: n1=E102H
n2 db 0feh n2=78H
result db ?
data ends Output: Quo = 1E0H
code segment Rem = 02H
assume cs:code,ds:data
main:mov ax,data Input: n1=1122H
mov ds,ax n2= 33H
mov al, n1
cbw Output: 56H
mov bl, n2
idiv bl
mov result, al
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program for division of two signed 8 bit numbers is executed and the output is verified .

Department of Electronics and Communication Engineering Page 28 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.4.2 16 -bit signed division.

Start

Initialize Data Segment & Code segment

Allocate memory to store result.


Initialize two signed 16-bit numbers.

Store DS reg. by starting address of data segment.

Convert one of the byte to word or word to double word

Divide the word by byte or double word by word using signed division

Store the result in memory

Code ends end main

Department of Electronics and Communication Engineering Page 29 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.4.2. Aim : Write an ALP for 16-bit signed division

Software Required : MASM Assembler

16 bit signed division


Input: n1=FAEBH
data segment n2=1234H
n1 dw FAEBh Output:Quo=DH
n2 dw 1234h Rem=00H
result dw ?
data ends
code segment Input: n1= FFCC
assume cs:code,ds:data n2 = 1234
main:mov ax,data
mov ds,ax Output: Quo: E H
mov ax, n1
cwd Rem: 0H
mov bx, n2
idiv bx
mov result, ax
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program for division of two signed 16 bit numbers is executed and the output is verified

Department of Electronics and Communication Engineering Page 30 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.4.3. 8-bit Unsigned division.

Start

Initialize Data Segment & Code segment

Allocate memory to store result.


Initialize two unsigned 8- bit numbers.

Store DS reg. by starting address of data segment.

Convert one of the byte to word or word to double word by storing 00 in higher byte or word

Divide the word by byte or double word by word using unsigned division

Store the result in memory

Code ends end main

Department of Electronics and Communication Engineering Page 31 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.4.3. Write an ALP for 8- or 16-bit Unsigned division.

Software Required : MASM Assembler

8 bit Unsigned division

data segment Input: n1=40H


n1 db 40h n2=02H
n2 db 02h
result db 2dup(?) Output: Quo=20H
data ends Rem=00H
code segment Input: n1 = 60H
assume cs:code,ds:data n2 = 03H
main:mov ax,data
mov ds,ax Output: Quo = 20H
mov al, n1
cbw Rem=00H
mov bl, n2
div bl
mov result, al
mov result+1,ah
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program for division of two un signed 8 bit numbers is executed and the output is verified .

1.4.4. 16-bit Unsigned division.

Department of Electronics and Communication Engineering Page 32 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Start

Initialize Data Segment & Code segment

Allocate memory to store result.


Initialize two unsigned 16- bit numbers.

Store DS reg. by starting address of data segment.

Convert one of the byte to word or word to double word by storing 00 in higher byte or word

Divide the word by byte or double word by word using unsigned division

Store the result in memory

Code ends end main

Department of Electronics and Communication Engineering Page 33 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.4.4. Write an ALP for 8- or 16-bit Unsigned division


Software Required : MASM Assembler

data segment
n1 dw 2244h Input: n1=2244H
n2 dw 0d6h n2=D6H
result dw 2 dup(?)
data ends
code segment Output:Quo=28H
assume cs:code,ds:data Rem=D4H
main:mov ax,data
mov ds,ax
mov ax, n1
cwd
mov bx, n2
div bx
mov result, ax
mov result+2,dx
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program for division of two un signed 16 bit numbers is executed and the output is verified .

Department of Electronics and Communication Engineering Page 34 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

2.1 To check whether the given number is Positive or Negative.

Department of Electronics and Communication Engineering Page 35 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 2

AIM: WRITE A MICROPROCESSOR 8086 PROGRAM TO ILLUSTRATE THE FOLLOWING


LOGICAL OPERATIONS:

Software Required : MASM Assembler

2.1. Write an ALP to check whether the given number is Positive or Negative.

data segment
Msg1 db "Positive $"
Msg2 db "Negative $"
n1 db 88h
data ends

Department of Electronics and Communication Engineering Page 36 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov al, n1
test al,80h
jz pos
mov dx, offset Msg2
jmp display
pos: mov dx, offset Msg1
display: mov ah, 09h
int 21h
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program to check whether the given number is Positive or Negative is executed and the output is
verified
Input: 98H
Output: Negative

Input: 41H
Output:Positive

(Open ended experiment.)

2.2. To find the number of 1s and 0s in a given number.

Department of Electronics and Communication Engineering Page 37 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 38 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

2.2. Write an ALP to find the number of 1s and 0s in a given number.

Software Required : MASM Assembler

data segment
n1 db 82h
ones db 1dup(?)
zeros db 1dup(?)
data ends
code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov cx, 08h
mov al, n1
mov bl,00h
mov dl,00h
back: shr al, 01
jc l1
inc bl
jmp next
l1: inc dl
next: loop back
mov ones, dl
mov zeros,bl
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program to find the number of 1s and 0s in a given number is executed and the output is verified
Input: 48H 55H

Output: Ones=2 (dl=2) Ones=4 (dl=4)

Zeros=6 (bl=6) Zeros=4 (bl=4)

(Open ended experiment.)

Department of Electronics and Communication Engineering Page 39 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

2.3. To find the given number is 2 out of 5 code or not

Department of Electronics and Communication Engineering Page 40 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

2.3. Write an ALP to find the given number is 2 out of 5 code or not

Software Required : MASM Assembler

data segment
msg1 db "2 out of 5 code $"
msg2 db "Not 2 out of 5 code $"
n1 db 18h
data ends

code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov al, n1
mov cx, 05h
mov bl,00h
and al, 0e0h
jnz ncode
mov al, n1
back: rcr al, 1
jnc noinc
inc bl
noinc: loop back
cmp bl, 02h
jne ncodeor jnz
mov dx, offset msg1
jmp display
ncode: mov dx, offset msg2
display: mov ah, 09
int 21h
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program to find the given number is 2 out of 5 code or not is executed and the output is verified
Input: 78H
Output:Invalid

Input: 18H
Output:Valid
(Open ended experiment.)

2.4 To transfer a block of data from source to destination

Department of Electronics and Communication Engineering Page 41 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 42 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

2.4 Write an ALP to transfer a block of data from source to destination


Software Required : MASM Assembler

Data segment
Org 1000h
Num1 db 10h,20h,30h,40h,50h
Org 2000h
Num2 db 5 dup(?)
Count equ 05h
Data ends
Code segment
Assume cs:code,ds:data
Main:MOV AX,DATA
MOV DS,AX
LEA SI,Num1
LEA DI,Num2
MOV CL,count
Back:MOV AL,[SI]
MOV [DI],AL
INC SI
INC DI
Loop Back
MOV AH,4CH
INT 21H
Code ends
End main
RESULT: The program to transfer a block of data from source to destination is executed and the output is
verified

Department of Electronics and Communication Engineering Page 43 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

3.1.1 Conversion from Binary to BCD (8- or 16-

Initialize Data Segment & Code segment

Binary to BCD
Allocate memory to store result.

Initialize counter to 0.
Store DS reg. by starting address of data segment.

Divide the number/quotient by 10.

Take 8- or 16-bit data to a register.


Store the reminder in stack.

Binary to BCD is
N
Quotient = 0
?

Store the result in a memory Y

Retrieve the reminder from stack and store the lower nibble in lower nibble position of the regist

Code ends end main

Decrement the count

N is
Left shift the contents of register by 4-bits Count = 0
?

Return

Department of Electronics and Communication Engineering Page 44 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 3
WRITE A MICROPROCESSOR 8086 PROGRAM TO ILLUSTRATE THE FOLLOWING CODE CONVERSIONS
3.1.1 Aim : To Write an ALP to Convert Binary to BCD Software Required : MASM Assembler

data segment
bcd dw 2 dup(?)
data ends Input: FFFFH Input: AAAAH
code segment Output: 0006 5535 Output: 0004 3690
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov ax,0ffffh
call bintobcd
mov bcd,ax
mov bcd+2,bx
mov ah, 4ch
int 21h
bintobcd proc near
push dx
push cx
mov bx,10
mov cx,00
divide: mov dx,00
div bx
push dx
inc cx
cmp ax,00
jnz divide
mov bx,00
number: pop dx
or ax,dx
dec cx
jz term
shl ax,1
rcl bx,1
shl ax,1
rcl bx,1
shl ax,1
rcl bx,1
shl ax,1
rcl bx,1
jmp number
term: pop cx
pop dx
ret
bintobcd end p
code ends end main
RESULT: The program to convert Binary to BCD is executed and the output is verified

3.1.2 Conversion from BCD to Binary (8- or 16-bit)

Department of Electronics and Communication Engineering Page 45 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Start

Initialize Data Segment & Code segment

BCD to Binary
Allocate memory to store result.

Store DS reg. by starting address of data segment. Initialize counter to 0.

Divide the number/quotient by 10H.


Take 8- or 16-bit data to a register.

Store the reminder in stack.

BCD to Binary
is
N
Quotent = 0
?
Store the result in a memory
Y

Retrieve the reminder from stack and store the lower nibble in lower nibble position of the register
Code ends end main

Decrement the count

is
Left shift the contents of register by 4-bitsN count = 0
?

Return

3.1.2 Write an ALP to Convert BCD to Binary (16-bit)

Department of Electronics and Communication Engineering Page 46 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Software Required : MASM Assembler

data segment
bcd dw 1234h
bin dw 0000h
data ends
code segment Input: 1234H Input: 4321H
Output:04D2 Output:10E1
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov ax, 0000H
mov bx,0001H
call convert
mov bx,000AH
call convert
mov bx,0064H
call convert
mov bx,03E8H
call convert
mov ah,4ch
int 21h

convert proc near


mov ax,bcd
and ax,000Fh
mul bx
add bin,ax
mov cl,04
ror bcd,cl
ret
convert endp
code ends
end main

RESULT: The program to convert o BCD to Binary is executed and the output is verified

Department of Electronics and Communication Engineering Page 47 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 48 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

<OR> 3.1.2 Write an ALP to Convert BCD to Binary (16-bit)

Data segment

Bcd dw 4596h
Result dw 2dup(?)
Data ends

Code segment
Assume cs:code,ds:data
Main: mov ax,data
mov ds,ax
mov ax,bcd
mov bx,ax
mov al,ah
mov bh,bl
mov cl,04h
ror ah,cl
ror bh,cl
and ax,0f0fh
and bx,0f0fh
mov cx,ax
mov ax,0000h
mov al,ch
mov di,03e8h
mul di
mov dh,00h
mov dl,bl
add ax,dx
mov dx,ax
mov ax,0064h
mul cl
add dx,ax
mov ax,000Ah
mul bh
add ax,dx
mov result,ax
mov ah,4ch
int 21h
code ends
end main

Department of Electronics and Communication Engineering Page 49 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

3.2.1. conversion of ASCII code to Binary code

Start
A

Initialize Data Segment & Code segment is


Y
[AL] ≤ 39
?

Allocate memory to store Binary equivalent. N

is
Y
[AL] ≤ 46
?
Store DS reg. by starting address of data segment.
N

Subtract 20h by acc.


ASCII to Binary

Subtract 07h by acc.


Store the result

Subtract 30h by acc.


Code ends end main

By using OR and Shift operation store the number in any GPR

ASCII to Binary
Decrement counter

Save the contents of regs. in Stack


is
N
count = 0 B
?
Clear BX reg. and load counter by 04h
Y

B Return

Read a char. from keyboard using DOS function.

Department of Electronics and Communication Engineering Page 50 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1.2.1. Aim : To Write an ALP for conversion of ASCII code to Binary code
Software Required : MASM Assembler

data segment
res dw 1 dup (?)
data ends Input: 31 32 33 34 Input: 34 33 32 31

code segment Output: 1234H Output: 4321H

assume cs: code,ds:data


main:mov ax,data
mov ds,ax
call bin
mov res,bx
mov ah, 4ch
int 21h
bin proc near
push ax
mov bx,00h
mov cx,04h
mov dx,04h
back: mov ah,01h
int 21h
cmp al,39h
jbe skip
cmp al,46h
jbe skip1
sub al,20h
skip1: sub al,07h
skip: sub al,30h
or bl,al
dec dx
jz stop
shl bx,01h
shl bx,01h
shl bx,01h
shl bx,01h
stop: loop back
pop ax
ret
bin end p
code ends
end main
Note:

Input is through keyboard, so its ascii value will be actual input

RESULT: The program to convert o ASCII code to Binary code is executed and the output is verified

Department of Electronics and Communication Engineering Page 51 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

3.2.2. Binary to ASCII Code conversion

Department of Electronics and Communication Engineering Page 52 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Start Binary to ASCII

Save the contents of


Initialize Data Segment & Code segment regs. in Stack

Allocate memory to store ASCII equivalent. Take the higher nibble

is
Y higher nibble ≤ 9
Store DS reg. by starting address of data segment. ?

Take higher byte of data to Acc. Add 07h.

Add 30h.
Binary to ASCII

Store the result in Reg.


Store the result in memory

Take the higher nibble


Take lower byte of data to Acc.
is
Y higher nibble ≤ 9
?
Binary to ASCII
N

Store the result in memory Add 07h.

Add 30h.
Code ends end main

Store the result in Reg.

Return

Department of Electronics and Communication Engineering Page 53 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

3.2.2. Write an ALP for conversion of Binary code to ASCII code

Software Required : MASM Assembler

(a) For 16bit data: (b) For 8bit data:

data segment data segment

num db A2h,13h num db 3CH

res dw 2 dup (?) res dw 1 dup (?)

data ends data ends

code segment code segment

assume cs:code,ds:data assume cs:code,ds:data


main:mov ax,data main:mov ax,data
mov ds,ax mov ds,ax
mov ah,00h mov ah,00h
mov al,num mov al,num
call ascii call ascii

mov result,cl mov result,cl

mov result+1,bl mov result+1,bl

mov ah,4ch mov ah,4ch

int 21h int21h

Department of Electronics and Communication Engineering Page 54 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 55 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

; Procedure is same for both 8 / 16bit data, but proc is called twice for 16bit data

ascii proc near

push ax

and al,0f0h

mov cl,04h

ror al,cl

cmp al,09h

jbe skip1

add al,07h

skip1: add al,30h

mov bl,al

pop ax

and al,0fh

cmp al,09h

jbe skip2

add al,07h

skip2: add al,30h

mov cl,al

ret

ascii end p

code ends

end main

RESULT: The program to convert o Binary code to ASCII code is executed and the output is verified
Input: 4A01H Input: 003CH Input: 3C H Input: 4A H

Output: 34 41 30 31 Output: 30 30 33 43 Output: 33 43 ` Output: 34 41

(Open ended experiment.)

Department of Electronics and Communication Engineering Page 56 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

4.1. Transfer a String from source to destination

Start

Initialize Data Segment & Code segment

Initialize a string of length N &


Counter by string length.
Allocate memory to store the string.

Take starting address of data segment to


acc. And overlap data and extra segment.

Load starting addr. of source to source index reg. and destination addr. to destination index reg.

Clear direction flag

Transfer string byte by byte until count must become zero.

Code ends end main

Department of Electronics and Communication Engineering Page 57 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 4

WRITE A MICROPROCESSOR 8086 PROGRAM TO ILLUSTRATE THE FOLLOWING STRING


OPERATIONS:

4.1. Aim : To Write an ALP to transfer a String from source to destination

Software Required : MASM Assembler

data segment
Msgs db "Welcome to 8086 Lab$"
len equ ($ - Msgs)
Msgd db 25 dup (?)
Data ends

code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov es,ax
mov si, offset Msgs
mov di, offset Msgd
mov cx, len
cld
rep movsb
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program to transfer a String from source to destination is executed and the output is verified

Input: 0004H🡪WELCOME Input: 0004H🡪HORIZON

Output: 000CH🡪WELCOME Output: 000CH🡪 HORIZON

4.2. Reverse the given string.


Start
Department of Electronics and Communication Engineering Page 58 of 124

Initialize Data Segment & Code segment


Initialize a string of length N &
Counter by string length.
Allocate memory to store the string.
ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Take starting address of data segment to


acc. And overlap data and extra segment.

Load starting addr. of source to source index reg. and destination addr. to destination index reg.

Add String length – 1 to destination index reg.

Transfer a byte of string.

Increment source index reg. & decrement destination index reg.

Decrement count

is
N
count = 0
?

Code ends end main

4.2. Aim : To Write an ALP to reverse the given string.

Software Required : MASM Assembler

Department of Electronics and Communication Engineering Page 59 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

data segment
Msgs db "WELCOME$"
len equ ($ - Msgs)
Msgr db 25 dup(?)
Data ends
code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov es, ax
mov si, offset Msgs
mov di, offset Msgr
mov cx, len-1
add di, len-2
cld
reverse: movsb
dec di
dec di
loop reverse
mov byte ptr[di+len],’$’
mov dx,offset Msgr
mov ah,09h
int 21h
mov ah, 4ch
int 21h
code ends
end main
RESULT: The program to reverse a String is executed and the output is verified

Input: 0001🡪CODE ENDS Input: END MAIN

Output: 0006🡪ONE Output: 0006🡪ONE

4.3. Check whether the given string is Palindrome or not


Start

Initialize Data Segment & Code segment

Department of Electronics and Communication Engineering Page 60 of 124

Initialize Msg1 as “Palindrome $” &


Msg2 as “Not Palindrome $”. A
Initialize the string.
Allocate memory to store the string.
is
Reversed string N
Take starting address of data segment to =
ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem
acc. And overlap data and extra segment. Original string
?

r. of source to source index reg. and destination addr. to destination index reg. Y Print Msg2

Print Msg1

Add String length – 1 to destination index reg.

Code ends end main


Transfer a byte of string.

crement source index reg. & decrement destination index reg.

Decrement count

is
N
count = 0
?

Department of Electronics and Communication Engineering Page 61 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

4.3. Aim : To Write an ALP to check whether the given string is Palindrome or not

Software Required : MASM Assembler

data segment
Msgs db "APPA$"
len equ ($ - Msgs) Input:MALAYALAM
Msgr db 20 dup(0) Output:Palindrome
Msgp db "Palindrome $"
Msgn db "Not Palindrome $"
Data ends
Input: MICRO
code segment Output: Not Palindrome

assume cs:code,ds:data
main : mov ax,data
mov ds,ax
mov es, ax
mov si, offset Msgs
mov di, offset Msgr
mov cx, len-1
add di, len-2
cld
reverse: movsb
dec di
dec di
loop reverse
mov byte ptr[di+len],’$’
mov si, offset Msgs
mov di, offset Msgr
mov cx, len
repe cmpsb
jz pal
mov dx, offset Msgn
jmp display
pal: mov dx, offset Msgp
display: mov ah, 09
int 21h
mov ah, 4ch
int 21h
code ends
end main
RESULT: The program to to check whether the given string is Palindrome or not is executed and the output is verified

5.1 To find the largest number in an array


 

Department of Electronics and Communication Engineering Page 62 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 63 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 5

WRITE A MICROPROCESSOR 8086 PROGRAM TO ILLUSTRATE THE FOLLOWING SORTING


OPERATIONS:

5.1. Aim : To Write an ALP to find the largest number in an array

Software Required : MASM Assembler

data segment
array db 12h, 56h, 0feh, 34h, 90h, 0abh
len dw 06h
large db ?
data ends

code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov si, offset array
mov al, [si]
mov cx, len
dec cx
search: inc si
cmp al, [si]
jnc nochange
mov al, [si]
nochange: loop search
mov large, al
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program to find the largest number in an array is executed and the output is verified

Input: 76H,F2H,46H,18H,24H Input: 01H 05H 02H 04H 03H

Output: F2H Output: 05H

(Open ended experiment.)

5.2 To find the Smallest number in an array

Department of Electronics and Communication Engineering Page 64 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 65 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

5.2. Aim : To Write an ALP to find smallest number in an array

Software Required : MASM Assembler

data segment
array db 12h, 38h, 82h, 0cdh, 67h
len dw 05h
small db ?
data ends

code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov si, offset array
mov cx, len
dec cx
mov al, [si]
search: inc si
cmp al, [si]
jc nochange
mov al, [si]
nochange: loop search
mov small, al
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program to find the Smallest number in an array is executed and the output is verified

Input: 76H,F2H,34H,19H,01H Input: 01H 05H 02H 04H 03H

Output: 01H Output: 01H

(Open ended experiment.)

Department of Electronics and Communication Engineering Page 66 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

5.3 To sort the given array in an Ascending order

Department of Electronics and Communication Engineering Page 67 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

5.3. Aim: To Write an ALP to sort the given array in an Ascending order.

Software Required : MASM Assembler

data segment
array db 45h, 0adh, 81h, 76h, 0feh
len equ 05h
data ends

code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov bx, len-1
rpt: mov cx,bx
mov si,offset array
back: mov al.[si]
inc si
cmp al,[si]
jc skip
xchg al,[si]
dec si
mov [si,],al
inc si
skip: loop back
dec bx
jnz rpt
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program to sort the given array in an Ascending order.is executed and the output is verified

Input: 45H,ADH,81H,76H,FEH Input: 05H 04H 03H 02H 01H

Output: 45H,76H,81H,ADH.FEH Output: 01H 02H 03H 04H 05H

(Open ended experiment.)


5.4 To sort the given array in an Ascending order

Department of Electronics and Communication Engineering Page 68 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

5.4. Aim : To Write an ALP to sort the given number in Descending order

Department of Electronics and Communication Engineering Page 69 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Software Required : MASM Assembler

data segment
array db 45h, 0adh, 81h, 76h, 0feh
len equ 05h
data ends

code segment
assume cs:code,ds:data
main:mov ax,data
mov ds,ax
mov bx, len-1
rpt: mov cx,bx
mov si,offset array
back: mov al.[si]
inc si
cmp al,[si]
jnc skip
xchg al,[si]
dec si
mov [si,],al
inc si
skip: loop back
dec bx
jnz rpt
mov ah, 4ch
int 21h
code ends
end main

RESULT: The program to sort the given array in an Descending order. is executed and the output is verified
Input: 45H,ADH,81H,76H,FEH Intput: 01H 02H 03H 04H 05H

Output: FEH,ADH,81H,76H.45H Output: 05H 04H 03H 02H 01H

(Open ended experiment.)

Department of Electronics and Communication Engineering Page 70 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Algorithm:

1. LOAD R0 with value 30H (source pointer)


2. LOAD R1 with value 40H(destination PTR)
3. LOAD the count value 05H into R2
4. GET a byte from source
5. COPY it to destination
6. INCREMENT SRC PTR
7. INCREMENT DSTN PTR
8. LOOP until COUNTER = ZERO
9. END THE PROGRAM

Department of Electronics and Communication Engineering Page 71 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 6

ALP TO ILLUSTRATE THE FOLLOWING DATA TRANSFER OPERATIONS ON 8-BIT NUMBERS:

a) To move a block of data from source to destination.


b) To exchange the block of data from source to destination.
c) To arrange the series of numbers in ascending / descending order.

a) Aim : Write an ALP to MOVE A BLOCK OF DATA FROM SOURCE TO DESTINATION


Software Required : Keil µVision

MOV R0, #30


MOV R1, #40
MOV R2, # 05
BACK: MOV A, @R0
MOV @R1, A
INC R0
INC R1
DJNZ R2, BACK
END

TRIAL-01and 02

INPUT :

OUTPUT :
SOURCE

ADDRESS DATA

30H 01 05 DESTINATION

31H 02 04 ADDRESS DATA

32H 03 03 40H 01 05

04 02 41H 02` 04
33H
42H 03 03
34H 05 01
43H 04 ` 02

44H 05 01

RESULT: The program to move a block of data from source to destination.is executed and the output is verified

Department of Electronics and Communication Engineering Page 72 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Algorithm:

1. LOAD R0 with value 30H (source pointer)


2. LOAD R1 with value 40H(destination PTR)
3. LOAD the COUNT value 05H into R2
4. GET a byte from SOURCE & LOAD in A
5. GET a byte from DSTN & LOAD in R3
6. COPY it to DESTINATION
7. COPY it to SOURCE
8. INCREMENT SRC PTR
9. INCREMENT DSTN PTR
10. LOOP until COUNTER = ZER0
11.

Department of Electronics and Communication Engineering Page 73 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

b) Aim : Write an ALP to TO EXCHANGE THE BLOCK OF DATA FROM SOURCE TO DESTINATION

Software Required : Keil µVision

MOV R0, #30


MOV R1, #40
MOV R2, # 05
BACK: MOV A, @R0
MOV B, @R1
MOV @R1, A
MOV @R0, B
INC R0
INC R1
DJNZ R2, BACK
END

TRIAL -01
OUTPUT :

Before execution After execution

SRC DST SRC DST


ADDR DATA ADDR DATA ADDR DATA ADDR DATA
30 01 40 06 30 06 40 01
31 02 41 07 31 07 41 02
32 03 42 08 32 08 42 03
33 04 43 09 33 09 43 04
34 05 44 10 34 10 44 05

TRIAL-02
OUTPUT :

Before execution After execution

SRC DST SRC DST


ADDR DATA ADDR DATA ADDR DATA ADDR DATA
30 10 40 05 30 05 40 10
31 09 41 04 31 04 41 09
32 08 42 03 32 03 42 08
33 07 43 02 33 02 43 07
34 06 44 01 34 01 44 06

RESULT: The program to exchange block of data from source to destination.is executed and the output is verified
Algorithm

Department of Electronics and Communication Engineering Page 74 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1. LOAD the count value 06H in R1


2. DECREMENT count value
3. SAVE the value in ACC
4. COPY the value in ACC to R2
5. LOAD the array address 30H in R0
6. GET a byte into ACC
7. INCREMENT the array address
8. LOAD second byte in 40H RAM address
9. COMPARE 1st& 2nd byte, IF # , JUMP to EMP
10. IF equal, JUMP to LOC. NEXT
11. IF CY = 1, JUMP TO LOC.NEXT
12. LOAD the 1St byte in 2nd address
13. DECREMENT the pointer
14. LOAD the 2nd byte in 1St address
15. INCREMENT the pointer address
16. LOOP until inner counter R2 = 0
17. ; LOOP until counter R1 = 0
18. Terminate the program

Department of Electronics and Communication Engineering Page 75 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

c.1) Aim : Write an ALP TO ARRANGE THE SERIES OF NUMBERS IN ASCENDING ORDER

Software Required : Keil µVision

MOV R1, #06


DEC R1
PASS : MOV A, R1
MOV R2, A
MOV R0, #30
BACK: MOV A, @R0
INC R0
MOV 40, @R0
CJNE A, 40, TEMP
SJMP NEXT
TEMP: JC NEXT
MOV @R0, A
DEC R0
MOV @R0 ,40
INC R0
NEXT: DJNZ R2, BACK
DJNZ R1, PASS
END

OUTPUT :
Before execution After execution

ADDRESS DATA ADDRESS DATA

30H 09 30H 01
31H 02 31H 02
32H 10 32H 03
33H 01 33H 07
34H 03 34H 09
35H 07 35H 10

RESULT: The program TO ARRANGE THE SERIES OF NUMBERS IN ASCENDING ORDER .is executed and the
output is verified

Department of Electronics and Communication Engineering Page 76 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Algorithm:

1. LOAD THE COUNT VALUE 06H IN R1


2. DECREMENT COUNT VALUE
3. SAVE THE VALUE IN ACC
4. COPY YHE VALUE IN ACC TO R2
5. LOAD THE ARRAY ADDRESS 30H IN R0
6. GET A BYTE INTO ACC
7. INCREMENT THE ARRAY ADDRESS
8. LOAD SECOND BYTE IN 40H RAM ADDRESS
9. COMPARE 1st&2nd BYTE, IF # , JUMP TO EMP
10. IF EQUAL, JUMP TO LOC. NEXT
11. IF CY#1, JUMP TO LOC.NEXT
12. LOAD THE 1St BYTE IN 2nd ADDRESS
13. DECREMENT TE POINTER
14. LOAD THE 2nd BYTE IN 1St ADDRESS
15. INCREMENT THE POINTER ADDRESS
16. LOOP UNTIL INNNER COUNTER R2 = 0
17. LOOP UNTIL COUNTER R1 = 0
18. TERMINATE THE PROGRAM

Department of Electronics and Communication Engineering Page 77 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

c.2) Aim : Write an ALP TO ARRANGE THE SERIES OF NUMBERS IN DESCENDING ORDER.
Software Required : Keil µVision

MOV R1, #06


DEC R1
PASS : MOV A, R1
MOV R2, A
MOV R0, #30
BACK: MOV A, @R0
INC R0
MOV 40,@R0
CJNE A, 40, TEMP
SJMP NEXT
TEMP: JNC NEXT
MOV @R0, A
DEC R0
MOV @R0,40
INC R0
NEXT: DJNZ R2, BACK
DJNZ R1, PASS
END

OUTPUT :
Before execution After execution

ADDRESS DATA ADDRESS DATA

30H 01 30H 06
31H 02 31H 05
32H 03 32H 04
33H 04 33H 03
34H 05 34H 02
35H 06 35H 01

RESULT: The program TO ARRANGE THE SERIES OF NUMBERS IN DESCENDING ORDER .is executed and the
output is verified

Department of Electronics and Communication Engineering Page 78 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Algorithm:

1. Make CY = 0
2. LOAD the low byte i,e., A = E7h
A= A + 8D
3. Save the low byte in R6
4. LOAD the high byte i,e., A = 3Ch
5. A = A + 3B + CY
6. ; SAVE the high byte of SUM in R7

Department of Electronics and Communication Engineering Page 79 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 7

AIM: TO WRITE AN ASSEMBLY LANGUAGE PROGRAM FOR FOLLOWING OPERATIONS ON 16-BIT


NUMBERS.

Software Required : Keil µVision

(a) ADDITION
(b) SUBTRACTION
(c) MULTIPLICATION/SQUARE
(d) DIVISION
C

a) ADDITION OF TWO 16-BIT NUMBERS

CLR C
MOV A, #0E7
ADD A, #8D
MOV R6, A
MOV A, #3C
ADDC A, #3B
MOV R7, A
END

OUTPUT:

( Lower byte of the SUM )


( Higher byte of the SUM )

OR

MOV R0,#20H
MOV R1,#30H
MOV A,@R0
ADD A,@R1

RESULT: The Program for ADDITION OF TWO 16-BIT NUMBERS .is executed and th

Department of Electronics and Communication Engineering Page 80 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Algorithm

; MAKE CY = 0
; LOAD the low byte i.e., A = 62h
; A = A − 96 − CY
; SAVE the low byte in R6
; LOAD the high byte i.e., A = 27h
; A = A – 12 − CY
; SAVE the high byte of SUM in R7
; Transfers control to subroutine / ( Terminate the
program)

Department of Electronics and Communication Engineering Page 81 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

b) SUBTRACTION OF TWO 16-BIT NUMBERS

CLR C
MOV A, #62
SUBB A, #96
MOV R6, A
MOV A, #27
SUBB A, #12
MOV R7, A
END

OUTPUT :

( Lower byte of the SUM )


( Higher byte of the SUM )

RESULT: The Program for SUBTRACTION OF TWO 16-BIT NUMBERS .is executed and the output is verified

Department of Electronics and Communication Engineering Page 82 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

ALGORITHM:

1. Start.
2. Load the MSB’s of Data in two different registers.
3. Load the LSB’s of Data in other two different registers.
4. Successive multiplication is carried out.
5. The product obtained in the registers.
6. The output is stored in the registers.
7. End.

Department of Electronics and Communication Engineering Page 83 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

c) MULTIPLICATION / SQUARE OF TWO 16-BIT NUMBERS.

Org 0000h
mov r5,#00h
mov a,31h
mov b,33h
mul ab
mov 40h,a
mov r7,b
mov a,30h
mov b,33h
mul ab
addc a,r7
mov r7,a
mov a,b
addc a,#00h
mov r6,a
mov a,31h
mov b,32h
mul ab
addc a,r7
mov 41h,a
mov a,b
addc a,r6
mov r6,a
jnc xx
inc r5
xx:mov r6,a
mov a,30h
mov b,32h
mul ab
addc a,r6
mov 42h,a
mov a,b
addc a,r5
mov 43h,a
end

RESULT: The Program for MULTIPLICATION / SQUARE OF TWO 16-BIT NUMBER is executed and the output is verified

OUTPUT
Input 1 Output :
Src Address 1 Data Dst Address Data
30h FFh 40h 01
31h FFh 41h 00
32h FFh 42h FE
33h FFh 43h FF

Department of Electronics and Communication Engineering Page 84 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 85 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

d) DIVISION OF 16-BIT NUMBER BY A 8- BIT NUMBER.

mov a,40h
mov r0,#41h
mov b,60h
div ab
mov 50h,a
mov a,b
swap a
mov r1,a
mov a,@r0
anl a,#0f0h
swap a
add a,r1
mov b,60h
div ab
swap a
mov r2,a
mov a,b
swap a
mov r3,a
mov a,@ro
anl a,#0fh
add a,r3
mov b,60h
div ab
add a,r2
mov 51h,a
mov 52h,b
end

OUTPUT

Input 1 Output :
Src Address 1 Data Dst Address Data
40h FFh 50h ff
41h FFh 51h 3f
60h 04h

RESULT: The Program for DIVISION OF 16-BIT NUMBER BY A 8- BIT NUMBER is executed and the output is verified

Department of Electronics and Communication Engineering Page 86 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

ALGORITHM:
LOAD THE NUMBER 34H IN R0 REG.
1. // AND LOGICAL OPERATION

a. ; COPY THE NUM IN R0 TO ACC.

b. ; AND LOGICALLY 0FH WITH A, STORE RESULT IN A.


c. ; COPY VALUE IN A TO R1 REG.
2. // OR LOGICAL OPERATION

a. ; COPY THE NUM IN R0 TO ACC.

b. ; OR LOGICALLY 0FH WITH A, STORE RESULT IN A.


c. ; COPY VALUE IN A TO R2 REG.
3. // XOR LOGICAL OPERATION

a. ; COPY THE NUM IN R0 TO ACC.

b. ; XOR LOGICALLY 0FH WITH A, STORE RESULT IN A.


c. ; COPY VALUE IN A TO R3 REG.
4. // COMPLEMENT LOGICAL OPERATION

a. ; COPY THE NUM IN R0 TO ACC.

b. ; COMPLEMENT VALUE IN A, STORE RESULT IN A.


c. ; COPY VALUE IN A TO R4 REG.
5. // CLEAR LOGICAL OPERATION

a. ; COPY THE NUM IN R0 TO ACC.

b. ; CLEAR VALUE IN A (A = 0), STORE RESULT IN A.


c. ; COPY VALUE IN A TO R5 REG.

Department of Electronics and Communication Engineering Page 87 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 8

AIM: WRITE AN ALP TO ILLUSTRATE LOGICAL & BIT MANIPULATION


OPERATION

a) AND
b) OR
c) XOR
d) COMPLEMENT
e) CLEAR & SETTING A BIT.
f) ROTATE LOGICAL LEFT &RIGHT.
g) EXCHANGE OF UPPER & LOWER NIBBLE.

MOV R0, #34

MOV A, R0

ANL A, #0F
MOV R1, A

MOV A, R0

ORL A, #0F
MOV R2, A

MOV A, R0

XRL A, #0F
MOV R3,A

MOV A, R0

CPL A
MOV R4, A

MOV A, R0

CLR A
MOV R5, A

Department of Electronics and Communication Engineering Page 88 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

; COPY THE NUM IN R0 TO ACC.

; ROTATE THE A REG ONE BIT POSITION TO RIGHT.


; ROTATE THE A REG ONE BIT POSITION TO RIGHT.
; ROTATE THE A REG ONE BIT POSITION TO RIGHT.
; ROTATE THE A REG ONE BIT POSITION TO RIGHT.
; COPY VALUE IN A TO R6 REG.
6. // ROTATE LEFT LOGICAL OPERATION

; COPY THE NUM IN R0 TO ACC.

; ROTATE THE A REG ONE BIT POSITION TO LEFT.


; ROTATE THE A REG ONE BIT POSITION TO LEFT.
; ROTATE THE A REG ONE BIT POSITION TO LEFT.
; ROTATE THE A REG ONE BIT POSITION TO LEFT.
; COPY VALUE IN A TO R7 REG.
7. EXCHANGE OF UPPER & LOWER NIBBLE

; COPY THE NUM IN R0 TO ACC.

; INTERCHANGE THE NIBBLES IN A.


; COPY VALUE IN A TO B REG.

OUTPUT:

Department of Electronics and Communication Engineering Page 89 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

MOV A,
R0
RR A
RR A
RR A
RR A
MOV R6,
A

MOV A,
R0
RL A
RL A
RL A
RL A
MOV R7,
A

MOV A,
R0
SWAP A
MOV B,
A
INPUT: O
U
T
P
U
T
:

ADDRESS DATA
ADDRESS DATA

(AND) R1 04
R0 34H

(OR) R2 3F
(XOR) R3 3A
(CPL) R4 8A
(CLR) R5 00
(RRA) R6 45
(RLA) R7 25
(SWAP) B 43

Department of Electronics and Communication Engineering Page 90 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

RESULT: The Program TO ILLUSTRATE LOGICAL & BIT MANIPULATION OPERATION is executed and the
output is verified

Department of Electronics and Communication Engineering Page 91 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Algorithm :
1. ; LOAD THE (BCD) SRC ADDRESS 30H IN R0.
2. ; LOAD THE (ASCII) DSTN ADDRESS 40H INTO
R1.
3. ; LOAD count value of BCD digits of 03H TO R2.
4. ; MOVE BCD VALUE TO ACC.
5. ; OR CONTENTS OF A WITH IMMEDIATE
VALUE 30H
6. ; ASCII VALUE IN A IS STORED IN DSTN
ADDRESS
7. ; INCREMENT THE SRC ADDRESS
8. ; INCREMENT THEDSTN ADDRESS.
9. ; CHECK IF R2 = 0, JUMP TO LOC BACK
10. ; TERMINATE THE PROGRAM.

Department of Electronics and Communication Engineering Page 92 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 9

AIM: TO WRITE AN ALP TO ILLUSTRATE THE FOLLOWING CODE


CONVERSION ON 8-BIT NUMBERS.

a) BCD – ASCII
b) ASCII - BCD
c) ASCII – DECIMAL
d) DECIMAL – ASCII
e) HEX – DECIMAL
f) DECIMAL - HEX

a) BCD TO ASCII CODE CONVERSION.

MOV R0,
#30h
MOV R1,
#40H
MOV R2,
#03
BACK: MOV A,
@R0
ORL A,
#30
MOV @R1,
A
INC R0
INC R1
DJNZ R2, BACK
LCALL 0003

OUTPU
INPUT: T:

ASCII
UNPACKE DST
SRC D ADDRES DAT
ADDRES S A
S BCDDATA 40H
34h
0
30H 4

0
31H 5 41H 35h

Department of Electronics and Communication Engineering Page 93 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

42H 36h
32H 06

Result : The Program to convert BCD to ASCII Code Conversion is Executed and the output is
verified

Department of Electronics and Communication Engineering Page 94 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1. ; LOAD THE (ASCII) SRC ADDRESS OF 50H IN R0.


2. ; LOAD THE (BCD) DSTNADDRESS OF 40H IN R1.
3. ; MOVE ASCII VALUE IN ACC
4. ; INCREMENT THE SRC POINTER
5. ; LOAD NEXT ASCII VALUE IN R2 REG.
6. ; MASK THE HIGHER NIBBLE OF ACC.
7. ; SAVE THE BCD VALUE IN DSTN ADDRESS.
8. ; INCREMENT DSTN POINTER
9. ; COPY THE NEXT ASCII VALUE IN R2 TO ACC.
10. ; MASK HIGHER NIBBLE& SAVE LOWER NIBBLE
IN A
11. ; SAVE THE BCD VALU IN NEXT DSTN ADDRESS.
12. ; TERMINATE THE PROGRAM.

Algorithm :

Department of Electronics and Communication Engineering Page 95 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

b) ASCII TOBCD CODE CONVERSION.

MOV R0, #50h


MOV R1, #40H
MOV A, @R0
INC R0
MOV B, @R0
ANL A, #0Fh
MOV @R1, A
INC R1
MOV A, B
ANL A, #0F
MOV @R1, A
End

TRIAL-01:

INPUT: OUTPUT:

SR ASCI UNPACKE
C I DSTN D
DAT
ADDRESS A ADDRESS BCD DATA

50H 35h 40H 05h


51H 39h 41H 09h

TRIAL-02:

INPUT: OUTPUT:

SR ASCI UNPACKE
C I DSTN D
DAT
ADDRESS A ADDRESS BCD DATA

50H 36h 40H 06h


41H
51H 37h 07h

Department of Electronics and Communication Engineering Page 96 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Result : The Program to convert ASCII to BCD Code Conversion is Executed and the output is
verified

Department of Electronics and Communication Engineering Page 97 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1. ; LOAD SRC (ASCII) ADDRESS 40H IN R0 REGISTER.


2. ; LOAD DSTN(BCD) ADDRESS 50H INTO R1.
3. ; MOVE ASCII VALUE TO ACC
4. ; INCREMENT THE 5. SRC POINTER.
6. ; MASK HIGHER NIBBLE OF ACC.
7. ; EXCHANGE HIGHER & LOWER NIBBLE OF ACC.
8. ; MOVE SWAPED VALUE IN A TO R3.
9. ; MOVE VALUE R2 IN ACC.
10. ; MASK HIGHER NIBBLE & SAVE LOWER VALUE IN
ACC.
11. ; ADD FIRST BCD VALUE WITH SECOND BCD
VALUE.
12. ; SAVE THE PACKED BCD(DECIMAL) VALUE IN
DSTN
13. ; TERMINATE THE PROGRAM
Algorithm :

Department of Electronics and Communication Engineering Page 98 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

c) ASCII TO DECIMAL CODE CONVERSION.

MOV R0, #40


MOV R1, #50
MOV A, @R0
INC R0
ANL A, #0Fh
SWAP A
MOV R3,A
MOV A, @r0
ANL A, #0Fh
ADD A, R3
MOV @R1, A
End

TRIAL-01:

INPUT: OUTPUT:

SR ASCI PACKED
C I DSTN BCD
DAT (DECIMAL)
ADDRESS A ADDRESS DATA

40H
35h 50H 54h
41H 34h 51H

TRIAL-02:

INPUT: OUTPUT:

ASCI
SRC I DSTN PACKED BCD
ADDRES DAT ADDRES
S A S (DECIMAL) DATA

50H 65H
40H 36
51H
41H 35
Result : The Program to convert ASCII to Decimal Code Conversion is Executed and the
output is verified

Department of Electronics and Communication Engineering Page 99 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

1. ; LOAD DSTN (ASCII) ADDRESS 50H IN R1 REGISTER.


2. ; LOAD SRC (BCD) ADDRESS 40H INTO R0.
3. ; MOVE DECIMAL VALUE TO ACC
4. ; SAVE THE VALUE IN R2 REG.
5. ; MASK HIGHER NIBBLE& SAVE LOWER NIBBLE IN ACC.
6. ; OR THE 30H VALUE WITH A TO MAKE IT ASCII VALUE.
7. ; SAVE LOWER DIGIT ASCII VALUE IN DSTN.
8. ; COPY THE DECIMAL VALUE TO ACC.
9. ; MASK LOWER NIBBLE& SAVE HIGHER NIBBLE IN ACC.
10. ; EXCHANGE THE HIGHER & LOWER NIBBLE IN ACC.
11. ; OR THE 30H VALUE WITH A TO MAKE IT ASCII VALUE.
12. ; INCREMENT THE DESTINATION POINTER.
13. ; SAVE HIGHER DIGIT ASCII VALUE IN DSTN.
14. ; TERMINATE THE PROGRAM.
Algorithm :

Department of Electronics and Communication Engineering Page 100 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

d) DECIMAL TO ASCII CODE CONVERSION.


MOV
R1#50H
MOV
R0#40h
MOV A,
@R0
MOV R2, A
ANL A,
#0Fh
ORL A,
#30H
MOV @R1,
A
MOV A, R2
ANL A,
#F0H
SWAP A
ORL A, #30
INC R1
MOV @R1,
A
END

TRIAL-01:

INPUT: OUTPUT:

ASCI
SRC PACKED BCD DSTN I
(DECIMAL) DAT
ADDRESS DATA ADDRESS A

50
40H 95 H 35
51
41H H 39

TRIAL-02:

INPUT: OUTPUT:

ASCI
SRC PACKED BCD DSTN I
(DECIMAL) DAT
ADDRESS DATA ADDRESS A
Department of Electronics and Communication Engineering Page 101 of 124
ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

50
40H 85 H 35
51
41H H 38

Result : The Program to convert Decimal to ASCII Code Conversion is Executed and the
output is verified

Department of Electronics and Communication Engineering Page 102 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Algorithm :

; LOAD SRC (HEX) ADDRESS 40H INTO R0.


1. ; LOAD DSTN (DECIMAL) ADDRESS 50H IN R1 REGISTER.
2. ; LOAD THE HEX DECIMAL VALUE IN ACC.
3. ; LOAD 0AH (DECIMAL-10) IN B REG.
4. ; DIVIDE A BY B, SAVE QUOTIENT IN A,REMAINDER IN B
5. ;
SAV
E
THE
FIRS
T
REM
AIND
ER
IN
DST
N. 6.
7. ; INCREMENT THE DESTINATION POINTER.
8. ; LOAD 0AH IN B REG,
9. ; DIVIDE A BY B, SAVE QUOTIENT IN A,REMAINDER IN B
10. ;
SAV
E
THE
SECO
ND
REM
AIND
ER
IN
DST
N
11. ; INCREMENT THE DESTINATION POINTER
12. ; SAVE THE VALUE IN A TO DSTN.
13. ; TERMINATE THE PROGRAM.

Department of Electronics and Communication Engineering Page 103 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

e) HEX TO DECIMAL CODE CONVERSION.


MOV R0, #40h
MOV R1, #50h
MOV A, @R0
MOV B, #0Ah
DIV AB
MOV @R1, B
INC R1
MOV B, #0Ah
DIV AB
MOV @R1, B
INC R1
MOV @R1, A
End

TRIAL-01:

INPUT:

SRC HEX
ADDRESS DATA

98H DSTN DECIMAL


ADDRESS DATA
40H

02(REMAINDE
41H
R)
50H
: 05(REMAINDE
R
51H
TRIAL-02:

INPUT: OUTPUT

SRC HEX DSTN DECIMAL


ADDRESS DATA ADDRESS DATA

99H 03(REMAINDER)

40H 50H

05(REMAINDER

Department of Electronics and Communication Engineering Page 104 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

41H 51H

Result : The Program to convert Hex to Decimal Code Conversion is Executed and the output
is verified .

Algorithm :

1. ; LOAD SRC (DECIMAL) ADDRESS 40H INTO R0.


2. ; LOAD DSTN (HEX) ADDRESS 50H IN R1 REGISTER.
3. ; LOAD THE DECIMAL VALUE IN ACC.
4. COPY THE DECIMAL VALUE IN A TO R2 REG
5. ; MASK HIGHER NIBBLE & SAVE LOWER NIBBLE IN A.
6. ; SAVE THE VALUE IN R3 .
7. ; COPY THE HEXADECIMAL VALUE SAVED IN R2 TO A.
8. ; MASK LOWER NIBBLE & SAVE HIGHER NIBBLE IN A.
9. ; EXCHANGE THE HIGHER & LOWER NIBBLE IN ACC.
10. ; LOAD 0AH (DECIMAL-10) IN B REG.
11. ; MULTIPLY A & B values, STORE LBYTE =A, H BYTE = B.
12. ; ADD CONTENTS OF A & R3 ,STORE RESULT IN A.
13. ; LOAD hex-decimal value in destination ADDRESS.
14. ; TERMINATE THE PROGRAM.

Department of Electronics and Communication Engineering Page 105 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

f) DECIMAL TO HEXADECIMAL CODE CONVERSION.

MOV R0, #40h ; LOAD SRC (DECIMAL) ADDRESS 40H INTO R0.
MOV R1, #50H ; LOAD DSTN (HEX) ADDRESS 50H IN R1 REGISTER.
; LOAD THE DECIMAL VALUE IN
MOV A, @R0 ACC.
MOV R2, A ; COPY THE DECIMAL VALUE IN A TO R2 REG
; MASK HIGHER NIBBLE & SAVE LOWER NIBBLE IN
ANL A, #0Fh A.
MOV R3, A ; SAVE THE VALUE IN R3 .
; COPY THE HEXADECIMAL VALUE SAVED IN R2 TO
MOV A, R2 A.
; MASK LOWER NIBBLE & SAVE HIGHER NIBBLE IN
ANL A, #F0H A.
SWAP A ; EXCHANGE THE HIGHER & LOWER NIBBLE IN ACC.
; LOAD 0AH (DECIMAL-10) IN B
MOV B, #0AH REG.
; MULTIPLY A & B values, STORE LBYTE =A, H BYTE =
MUL AB B.
ADD A, R3 ; ADD CONTENTS OF A & R3 ,STORE RESULT IN A.
MOV @R1, A ; LOAD hex-decimal value in destination ADDRESS.
End ; TERMINATE THE PROGRAM.

TRIAL 01:

INPUT: OUTPUT:

SRC DECIMAL HEXADECIMA


DSTN L
ADDRESS DATA ADDRESS DATA

40H 35 50H 23h

TRIAL 02:

INPUT: OUTPUT:

SRC DECIMAL HEXADECIMA


DSTN L
ADDRESS DATA ADDRESS DATA

40H 25 50H 19H

Department of Electronics and Communication Engineering Page 106 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Result : The Program to convert Decimal to Hex Code Conversion is Executed and the output
is verified

Department of Electronics and Communication Engineering Page 107 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

TMOD Register (Timer Mode)


This register selects mode of the timers T0 and T1. As illustrated in the following picture, the
lower 4 bits (bit0 - bit3) refer to the timer 0, while the higher 4 bits (bit4 - bit7) refer to the timer
1.

Bits of this register have the following purpose:


 GATE1 starts and stops Timer 1 by means of a signal provided to the pin INT1
(P3.3):
o 1 - Timer 1 operates only if the bit INT1 is set
o 0 - Timer 1 operates regardless of the state of the bit INT 1
 C/T1 selects which pulses are to be counted up by the timer/counter 1:
o 1 - Timer counts pulses provided to the pin T1 (P3.5)
o 0 - Timer counts pulses from internal oscillator
 T1M1,T1M0 These two bits selects the Timer 1 operating mode.

GATE0 starts and stops Timer 1, using a signal provided to the pin INT0 (P3.2):
o 1 - Timer 0 operates only if the bit INT0 is set
o 0 - Timer 0 operates regardless of the state of the bit INT0
 C/T0 selects which pulses are to be counted up by the timer/counter 0:
o 1 - Timer counts pulses provided to the pin T0(P3.4)
o 0 - Timer counts pulses from internal oscillator
 T0M1,T0M0 These two bits select the Timer 0 operating mode.

T1M1 T1M0 Mode Description


0 0 0 13-bit timer
0 1 1 16-bit timer
1 0 2 8-bit autoreload
1 1 3 Split mode

Department of Electronics and Communication Engineering Page 108 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 10

AIM: PROGRAMMING AND VERIFYING TIMER, INTERUPTS AND UART OPERATIONS


IN 8051 MICROCONTROLLER

10.1. Write an ALP to verify the Timer in 8051 Microcontroller.

MOV TMOD, #00H


AGAIN: MOV TL0, #01BH
MOV TH0,#1AH
SETB P2.3
ACALL DELAY
MOV TL0, #04H
MOV TH0, #54H
CLR P2.3
ACALL DELAY
SJMP AGAIN
DELAY: SETB TR0
WAIT: JNB TF0, WAIT
CLR TR0
CLR TF0
RET

Result : The Program to verify the Timer in 8051 Microcontroller is Executed and the output is
verified

Department of Electronics and Communication Engineering Page 109 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Serial port should be configured prior to being used. That determines how many bits one
serial “word” contains, what the baud rate is and what the pulse source for synchronization is.
All bits controlling this are stored in the SFR Register SCON (Serial Control)

SM0 - bit selects mode


 SM1 - bit selects mode
 SM2 - bit is used in case that several microcontrollers share the same interface. In
normal circumstances this bit must be cleared in order to enable connection to
function normally.
 REN - bit enables data receiving via serial communication and must be set in
order to enable it.
 TB8 - Since all registers in microcontroller are 8-bit registers, this bit solves the
problem of sending the 9th bit in modes 2 and 3. Simply, bits content is sent as
the 9th bit.
 RB8 - bit has the same purpose as the bit TB8 but this time on the receiver side.
This means that on receiving data in 9-bit format , the value of the last ( ninth)
appears on its location.
 TI - bit is automatically set at the moment the last bit of one byte is sent when the
USART operates as a transmitter. In that way processor “knows” that the line is
available for sending a new byte. Bit must be clear from within the program!
 RI - bit is automatically set once one byte has been received. Everything
functions in the similar way as in the previous case but on the receive side. This is
line a “doorbell” which announces that a byte has been received via serial communication. It
should be read quickly prior to a new data takes its place. This
bit must also be also cleared from within the program!

Department of Electronics and Communication Engineering Page 110 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

10.2. Write an ALP to illustrate the Interrupts and UART operations in 8051 Microcontroller.

PROGRAM 1:

MOV TMOD,#20H
MOV TH1,-3H
MOV SCON,#50H
SETB TR1
AGAIN :MOV SBUF,#’A’
WAIT:JNB TI,WAIT
CLR TI
SJMP AGAIN

OUTPUT :
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

PROGRAM 2:

MOV TMOD, #20H


MOV TH1, #-6
MOV SCON, #50H
SETB TR1
AGAIN: MOV A, #”F”
ACALL SEND
AGAIN: MOV A, #”O”
ACALL SEND
AGAIN: MOV A, #”U”
ACALL SEND
AGAIN: MOV A, #”R”
ACALL SEND
AGAIN: MOV A, #” ”
ACALL SEND
SJMP AGAIN
SEND: MOV SBUF, A
WAIT: JNB TI, WAIT
CLR TI
RET

OUTPUT :

FOUR FOURFOURFOURFOURFOUR
Result : The Program to illustrate the Interrupts and UART operations in 8051 Microcontroller is
Executed and the output is verified

Department of Electronics and Communication Engineering Page 111 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

STEPPER MOTOR CONTROL

STEPPER MOTOR CONTROL

W1 W2 W3 W4
1 1 0 0
0 1 1 0
0 0 1 1
1 0 0 1
1 1 0 0
0 1 1 0
0 0 1 1
1 0 0 1

Department of Electronics and Communication Engineering Page 112 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 11

AIM: WRITE AN ALP PROGRAM TO ILLUSTRATE STEPPER MOTOR


CONTROL INTERFACE TO 8051.

Program: (Continuous Rotation)

ORG 0000H
MOV A, #33H
BACK: MOV P0, A
RL A
ACALL DELAY
SJMP BACK
DELAY: MOV R0, #10H
LOOP1: MOV R1, #0FFH
LOOP2: DJNZ R1, LOOP2
DJNZ R0, LOOP1
RET

Program: (Angle Rotation)

ORG 0000H
MOV A, #66H
MOV R0, #45H
BACK: MOV P0, A
RR A
ACALL DELAY
DJNZ R0, BACK
HERE: SJMP HERE
DELAY: MOV R1, #0FFH
LOOP1: MOV R2, #0FFH
LOOP2: DJNZ R2, LOOP2
DJNZ R1, LOOP1
RET

Result : The Program TO ILLUSTRATE STEPPER MOTOR CONTROL INTERFACE


TO 8051 Microcontroller is Executed and the output is verified

Department of Electronics and Communication Engineering Page 113 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 114 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 12

AIM: WRITE AN ALP PROGRAM TO ILLUSTRATE LED INTERFACE TO 8051.

Program:

ORG 0000H
MOV A, #25H
BACK: MOV P0, A
ACALL DELAY
CPL A
SJMP BACK
DELAY: MOV R0, #10H
LOOP1: MOV R1, #0FFH
LOOP2: MOV R2, #0FFH
LOOP3: DJNZ R2, LOOP3
DJNZ R1, LOOP2
DJNZ R0, LOOP1
RET

Result : The Program TO ILLUSTRATE LED INTERFACE TO 8051 Microcontroller is


Executed and the output is verified

Department of Electronics and Communication Engineering Page 115 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 116 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 13

Department of Electronics and Communication Engineering Page 117 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

AIM: WRITE AN ALP PROGRAM TO ILLUSTRATE LCD INTERFACE TO 8051.

Program:

ORG 0000H DISP: MOV P0, A


MOV A, #38H(use2 lines in 5X7) SETB P3.7
ACALL CMND CLR P3.6
MOV A, #0FH(making LCD on,cursor blinking on)SETB P3.5
ACALL CMND ACALL DELAY
MOV A, #06H(incrementing cursor position) CLR P3.5
ACALL CMND RET
MOV A, #82H(cursor1,line1) DELAY: MOV R3, #50H
ACALL CMND BACK: MOV R4, #0FFH
BACK1: DJNZ R4, BACK1
MOV A, #’D’ DJNZ R3, BACK
ACALL DISP RET
MOV A, #’S’ END
ACALL DISP
MOV A, #’P’
ACALL DISP
MOV A, #0C1H
ACALL CMND
MOV A, #’L’
ACALL DISP
MOV A, #’A’
ACALL DISP
MOV A, #’B’
ACALL DISP
HERE: SJMP HERE
CMND: MOV P0,A
CLR P3.7
CLR P3.6
SETB P3.5
ACALL DELAY
CLR P3.5
RET
Result : The Program TO ILLUSTRATE LCD INTERFACE TO 8051 Microcontroller is
Executed and the output is verified

Department of Electronics and Communication Engineering Page 118 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 119 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

EXPERIMENT NO: 14

AIM: WRITE AN ALP PROGRAM TO ILLUSTRATE LED & SWITCH INTERFACE


TO 8051.

Program:

ORG 0000H
MOV P1, #0FFH
BACK: MOV A, P1
CJNE A, #0FFH, CHECK
SJMP BACK
CHECK: ACALL DELAY
MOV A, P1
CPL A
MOV p0, A
SJMP BACK
DELAY: MOV R0, #10H
LOOP1: MOV R1, #0FFH
LOOP2: DJNZ R1, LOOP2
DJNZ R0, LOOP1
RET

Result : The Program TO ILLUSTRATE LED INTERFACE TO 8051 Microcontroller is


Executed and the output is verified

Department of Electronics and Communication Engineering Page 120 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Department of Electronics and Communication Engineering Page 121 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Microprocessor 8086 Viva Questions


1.What is a Microprocessor?
2. What are the 4 Segments?
3. What is Bandwidth ?
4. What is Clock Speed ?
5. What are the features of Intel 8086 ?
6. What is Logical Address:?
•     7. What is The Effective Address:
8. What is Physical Address?
9.What are the flags in 8086?
10.Why crystal is a preferred clock source?
11.What is Tri-state logic?
12.What happens when HLT instruction is executed in processor?
13.What is Program counter?
14.What is 1st / 2nd / 3rd / 4th generation processor?
15.Name the processor lines of two major manufacturers?
16.How many bit combinations are there in a byte?
17.Have you studied buses? What types?
18.What is the Maximum clock frequency in 8086?
19.What is meant by Maskable interrupts?
20.What is Non-Maskable interrupts?
21.What are the different functional units in 8086?
22.What are the various segment registers in 8086?
23.What does EU do?
24.Which Stack is used in 8086? k is used in 8086?
25.What are the flags in 8086?
26.What is SIM and RIM instructions?
27.What are the different types of Addressing Modes?
28.What are the General Data Registers & their uses?
29.What are Segment Registers & their uses?
30.What are Flag registers?
31.What does the 8086 Architecture contain?
32) What are Data Copy/Transfer Instructions?
33. What are Machine Control Instructions?
34) What are Flag Manipulation Instructions?
35) What are String Instructions?
36) What are different parts for 8086 architecture?
37.What is an Interrupts
38. What is an Opcode?
39.What is an Operand?
40.Explain the difference between a JMP and CALL instruction?
41.What is meant by Polling?
42.What is meant by Interrupt?
43.What is an Instruction?
44.What is Microcontroller and Microcomputer?
45.What is Assembler?
46.Define Variable?
47.Explain Dup?
48.Define Pipelining?
49.What is the use of HLDA?
50. Explain about "LEA"?
51. Difference between "Shift" and "Rotate".
52. Explain about .MODEL SMALL?
53.Difference between JMP and JNC?54.List the String Manipulation Commands?
5

Department of Electronics and Communication Engineering Page 122 of 124


ECE52 – Microcontrollers Lab Manual V sem [2020 -2021] - V Sem

Microcontrller 8051 Viva Questions


1. Introduction Of 8051 Microcontroller Architecture?
2. Intel 8051 Follows Which Architecture?
3. What Is The Difference Between Harvard Architecture And Von Neumann
Architecture?
4. 8051 Was Developed Using Which Technology?
5. Why 8051 Is Called 8 Bit Microcontroller?
6. What Is The Width Of Data Bus?
7. What Is The Width Of Address Bus?
8. List Out The Features Of 8051 Microcontroller?
9. What Location Code Memory Space And Data Memory Space Begins?
10. How Much On Chip Ram Is Available?
11. List Out Addressing Modes In Mcs-51
12. How Much Total External Data Memory That Can Be Interfaced To The 8051?
13. What Is Special Function Registers (sfr)?
14. Give Example Of Bit Address And Byte Address?
15. What Are The Types Of Interrupts In 8051?
16. What Are The Four Distinct Types Of Memory In 8051?
17. Tell The Addresses Which Are Bit Addressable?
18. What Is Lst File?
19. What Is Equ?
20. How Are Labels Named In Assembly Language?
21. Are All The Bits Of Flag Register Used In 8051?
22. Which Bit Of The Flag Register Is Set When Output Overflows To The Sign Bit?
23. Can Port 0 Be Used As Input Output Port?

Department of Electronics and Communication Engineering Page 123 of 123

You might also like