EXPERIMENT 2
DATA TRANSFER/EXCHANGE
AIM: To develop ALPs for 8051 to transfer and exchange a set of data between specified locations.
PROGRAM:
A)DATA TRANSFER
Source location : 08H-0CH, destination location : 40H – 44H, data set = 5 numbers
ORG 0x0000 // program to be stored in memory locations 0x0000 onwards
MOV 08H, #40H // store 5 numbers in the locations from 08H onwards
MOV 09H, #15H
MOV 0AH, #75H
MOV 0BH, #08H
MOV 0CH, #56H
MOV R0, #08H // set source pointer
MOV R1, #40H // set target pointer
MOV R2, #05 // set count register
LOOP1: MOV A, @R0 // transfer a data to target location
MOV @R1, A
INC R0
INC R1
DJNZ R2, LOOP1 // if count is not zero, transfer the next data
HERE: SJMP HERE
END
B) DATA EXCHANGE BETWEEN SPECIFIED LOCATIONS
Set 1 location : 08H-0CH, set 2 location : 40H – 44H, data set = 5 numbers
ORG 0x0000 // program to be stored in memory location 0x0000 onwwards
MOV 08H, #40H // store 5 numbers of set1 in locations from 08H
MOV 09H, #15H
MOV 0AH, #75H
MOV 0BH, #08H
MOV 0CH, #56H
MOV 40H, #54H // store 5 numbers of set2 in locations from 40H
MOV 41H, #26H
MOV 42H, #1CH
MOV 43H, #9BH
MOV 44H, #72H
MOV R0, #08H // set the first pointer
MOV R1, #40H // set the second pointer
MOV R2, #05 // set count register
LOOP1: MOV A, @R0 // exchange a data between the locations
XCH A, @R1
MOV @R0, A
INC R0
INC R1
DJNZ R2, LOOP1 // if count is not zero, exchange the next data
HERE: SJMP HERE
END
RESULT:
Developed the ALPs for data transfer and exchange operations between specified locations in 8051 using
KEIL IDE simulator and verified.
A) DATA TRANSFER
Input :
Location 08H 09H 0AH 0BH 0CH
Value 40H 15H 75H 08H 56H
Output :
Location 40H 41H 42H 43H 44H
Value 40H 15H 75H 08H 56H
B) DATA EXCHANGE BETWEEN SPECIFIED LOCATIONS
Input : Set1
Location 08H 09H 0AH 0BH 0CH
Value 40H 15H 75H 08H 56H
Set2
Location 40H 41H 42H 43H 44H
Value 54H 26H 1CH 9BH 72H
Output :
Set1
Location 08H 09H 0AH 0BH 0CH
Value 54H 26H 1CH 9BH 72H
Set2
Location 40H 41H 42H 43H 44H
Value 40H 15H 75H 08H 56H
EXPERIMENT 3
LARGEST / SMALLEST NUMBER
AIM: To develop ALPs for 8051 to obtain the largest / smallest number from the given data set.
PROGRAM:
A) LARGEST NUMBER
Numbers in data set : 6, Data location : 15H – 1AH
ORG 0X0000 // program to store in memory from location 0x0000
MOV 15H, #18H // store 6 numbers locations from 15H
MOV 16H, #40H
MOV 17H, #30H
MOV 18H, #15H
MOV 19H, #08H
MOV 1AH, #56H
MOV R0, #15H //set source pointer
MOV R1, #05 //set count register (count is one less than total numbers)
MOV A, @R0 //load first value to Accumulator
BACK: INC R0
MOV B, @R0 //load next value to register B
CJNE A, B, NEXT //compare the registers A and B
NEXT: JNC SKIP //if register A is higher than register B, skip the exchange
XCH A, B
SKIP: DJNZ R1, BACK //if count is not zero, get the next value and repeat comparison
MOV 30H, A //store the largest number in the location 30H
HERE: SJMP HERE
END
B) SMALLEST NUMBER
Numbers in data set : 6, Data location : 15H – 1AH
ORG 0X0000 // program to store in memory from location 0x0000
MOV 15H, #18H // store 6 numbers locations from 15H
MOV 16H, #40H
MOV 17H, #30H
MOV 18H, #15H
MOV 19H, #08H
MOV 1AH, #56H
MOV R0, #15H //set source pointer
MOV R1, #05 //set count register (count is one less than total numbers)
MOV A, @R0 //load first value to Accumulator
BACK: INC R0
MOV B, @R0 //load next value to register B
CJNE A, B, NEXT //compare the registers A and B
NEXT: JC SKIP //if register A is lesser than register B, skip the exchange
XCH A, B
SKIP: DJNZ R1, BACK //if count is not zero, get the next value and repeat comparison
MOV 30H, A //store the smallest number in the location 30H
HERE: SJMP HERE
END
RESULT:
Developed the ALPs for obtaining the largest and smallest number from the given data set in 8051 using
KEIL IDE simulator and verified.
A) LARGEST NUMBER
Input :
Location 15H 16H 17H 18H 19H 1AH
Value 18H 40H 30H 15H 08H 56H
Output :
Location 30H
Value 56H
B) SMALLEST NUMBER
Input :
Location 15H 16H 17H 18H 19H 1AH
Value 18H 40H 30H 15H 08H 56H
Output :
Location 30H
Value 08H
EXPERIMENT 4
ASCENDING / DESCENDING ORDER
AIM: To develop an ALP for 8051 to sort the numbers in ascending / descending order.
PROGRAM:
A) ASCENDING ORDER
Numbers in data set : 5, Data location : 15H – 19H
ORG 0X0000 // program to be stored in memory locations 0x0000 onwards
MOV R2, #04H // count for loop 1(count is one less than the total numbers)
LOOP1: MOV R0, #15H // source pointer 1
MOV A, R0
INC A
MOV R1, A // source pointer 2
MOV A, R2
MOV R3, A // count for loop 2
LOOP2: MOV A, @R0 // get the first number to Accumulator
MOV B, @R1 // get the next number to register B
CJNE A, B, NEXT // compare registers A and B
NEXT: JC SKIP // if register A is smaller than B, skip the exchange
XCH A, B
MOV @R0, A
MOV @R1, B
SKIP: INC R0
INC R1
DJNZ R3, LOOP2 // if count is not zero, repeat the LOOP2 to complete the pass
DJNZ R2, LOOP1 // if count is not zero, repeat LOOP1 for the next pass
HERE: SJMP HERE
END
B) DESCENDING ORDER
Numbers in data set : 5, Data location : 15H – 19H
ORG 0X0000 // program to be stored in memory locations 0x0000 onwards
MOV R2, #04H // count for loop 1(count is one less than the total numbers)
LOOP1: MOV R0, #15H // source pointer 1
MOV A, R0
INC A
MOV R1, A // source pointer 2
MOV A, R2
MOV R3, A // count for loop 2
LOOP2: MOV A, @R0 // get the first number to Accumulator
MOV B, @R1 // get the next number to register B
CJNE A, B, NEXT // compare registers A and B
NEXT: JNC SKIP // if register A is smaller than B, skip the exchange
XCH A, B
MOV @R0, A
MOV @R1, B
SKIP: INC R0
INC R1
DJNZ R3, LOOP2 // if count is not zero, repeat the LOOP2 to complete the pass
DJNZ R2, LOOP1 // if count is not zero, repeat LOOP1 for the next pass
HERE: SJMP HERE
END
RESULT:
Developed the ALPs for sorting the given set of numbers in ascending and descending order in 8051 using
KEIL IDE simulator and verified.
A) ASCENDING ORDER
Input :
Location 15H 16H 17H 18H 19H
Value 40H 15H 75H 08H 56H
Output :
Location 15H 16H 17H 18H 19H
Value 08H 15H 40H 56H 75H
B) DESCENDING ORDER
Input :
Location 15H 16H 17H 18H 19H
Value 40H 15H 75H 08H 56H
Output :
Location 15H 16H 17H 18H 19H
Value 75H 56H 40H 15H 08H