Friday, 16 September 2016

Program to display the message in 8051

ORG 0000
MOV DPTR,#MY_DATA
MOV R0,#50H
MOV R2,#5H
REPEAT : CLR A
MOVC A,@A+DPTR
MOV @R0,A
INC DPTR
INC R0 
DJNZ R2,REPEAT
HERE :SJMP HERE
ORG 240H
 MY_DATA : DB " HELLO"
END

Program to perform factorial of a number (8051)

MOV DPTR,#1000H
MOVX A,@DPTR
MOV R1,A
MOV A,#01H
LOOP: MOV B,R1
MUL AB
INC DPTR
DJNZ R1,LOOP
END

Program to perform 16 bit BCD addition in 8051

MOV DPTR,#2080H
MOV A,#20H
MOV B ,#10H
ADDC A,DPL
DA A  
MOV A,B
DA A
ADDC A,DPH
MOV B,A
DA A
MOV A,DPL
END

Program to transfer n numbers from port 1 to port 2 in 8051

MOV A,#0FFH
MOV P0,A
MOV A,P0
MOV B,#10
DIV AB
MOV R7,B
MOV B,#10
DIV AB
MOV R6,B
MOV R5,A
END

Program for block transfer from one address to other (8051)

MOV R0,#30H
MOV R1,#50H
MOV R3,#8
RETURN : MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R3, RETURN
END

Program to find the sum of 10 numbers stored in the array (8051)

MOV R0,#50H
MOV R2,#6
CLR A
MOV R7,A
XYZ: ADD A,@R0
JNC NEXT
INC R7
NEXT: INC R0
DJNZ R2 , XYZ  
END

How to sort n numbers(Bubble sort ) in 8051

MOV R0,#09H
AGAIN:MOV DPTR,#1000H
MOV R1,#09H
BACK:MOV R2,DPL
MOVX A,@DPTR
MOV B,A
INC DPTR
MOVX A,@DPTR
CJNE A,B ,NEXT
AJMP SKIP
NEXT:JNC SKIP
MOV DPL,R2
MOVX @DPTR,A
INC DPTR
MOV A,B
MOVX @DPTR,A
SKIP:DJNZ R1,BACK
DJNZ R0,AGAIN
END