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

Data Transfer

This document contains an assembly language program to: 1) Transfer data between memory locations using a FOR loop. 2) Exchange data between two memory locations. 3) Find the largest element in an array and store it in a specific memory location using comparisons in a FOR loop. 4) Sort an array of data in ascending/descending order using the bubble sort algorithm with nested FOR loops to compare and exchange elements. The program is tested on an 8051 microcontroller and results are shown before and after each section's execution.

Uploaded by

Pragathish
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Data Transfer

This document contains an assembly language program to: 1) Transfer data between memory locations using a FOR loop. 2) Exchange data between two memory locations. 3) Find the largest element in an array and store it in a specific memory location using comparisons in a FOR loop. 4) Sort an array of data in ascending/descending order using the bubble sort algorithm with nested FOR loops to compare and exchange elements. The program is tested on an 8051 microcontroller and results are shown before and after each section's execution.

Uploaded by

Pragathish
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Microcontrollers Lab-10ESL47 2015-16

Experiment no. 1 : Data Transfer Programming


a. Write an assembly language program to transfer N = ___ bytes of data
from location A: _______h to location B: _______h.

Let N = 05h, A: 30h B: 40h


mov r0,#30h //source address
mov r1,#40h //destination address
mov r7,#05h //Number of bytes to be moved
back: mov a,@r0
mov @r1,a
inc r0
inc r1
djnz r7,back //repeat till all data transferred
end

Result:

Before Execution:

After Execution:

Dept. of EEE, C.I.T., Gubbi 5


Microcontrollers Lab-10ESL47 2015-16

b. Write an assembly language program to exchange N = ___h bytes of data


at location A: _____h and at location B: _____h.

Let N = 05h A: 30h B: 40h


mov r0,#30h //source address
mov r1,#40h //destination address
mov r7,#05h //count, the number of data to be exchanged
back: mov a,@r0
mov r4,a
mov a,@r1
mov @r0,a
mov a,r4
mov @r1,a
inc r0
inc r1
djnz r7,back
end
Result:
Before Execution:

After Execution:

Dept. of EEE, C.I.T., Gubbi 6


Microcontrollers Lab-10ESL47 2015-16

c. Write an assembly language program to find the largest element in a


given array of N =___ h bytes at location 4000h. Store the largest element
at location 4062h.

Let N = 06h
mov r3,#6 //length of the array
mov dptr,#4000H //starting address of array
movx a,@dptr
mov r1,a

nextbyte: inc dptr


movx a,@dptr
clr c //reset borrow flag
mov r2,a //next number in the array
subb a,r1 //other Num-Prev largest no.
jc skip // JNC FOR SMALLEST ELEMENT
mov a,r2 //update larger number in r1
mov r1,a

skip: djnz r3,nextbyte


mov dptr, #4062H //location of the result-4062h
mov a,r1 //largest number
movx @dptr,a //store at #4062H
end

Result:

Before Execution:

After Execution:

Dept. of EEE, C.I.T., Gubbi 7


Microcontrollers Lab-10ESL47 2015-16

d. Write an assembly language program to sort an array of N =____ h bytes


of data in ascending/descending order stored from location 9000h.
(Using bubble sort algorithm)

Let N = 06h
mov r0,#05H //count (N-1) array size = N
loop1: mov dptr, #9000h //array stored from address 9000h
mov r1,#05h //initialize exchange counter
loop2: movx a, @dptr //get number from array and store in B register
mov b, a
inc dptr
movx a, @dptr //next number in the array
clr c //reset borrow flag
mov r2, a //store in R2
subb a, b //2nd-1st No, since no compare instruction in 8051
jnc noexchg // JC - FOR DESCENDING ORDER
mov a,b //exchange the 2 nos in the array
movx @dptr,a
dec dpl //DEC DPTR - instruction not present
mov a,r2
movx @dptr,a
inc dptr

noexchg: djnz r1,loop2 //decrement compare counter


djnz r0,loop1 //decrement pass counter
end

Result:
Before Execution:

After Execution :( Ascending order)

Note:
Analyze the bubble sort algorithm for the given data. Also try with different sorting
algorithms.

Dept. of EEE, C.I.T., Gubbi 8

You might also like