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

How to write a Program to perform Fibonacci series (8051)

ORG 0H
MOV R0,#30H
MOV @R0,#00H
MOV R1,#31H
MOV @R1,#01H
MOV R2,#09H
MOV A,#01H
BACK:ADD A,@R0
INC R0
INC R1
MOV @R1,A
DJNZ R2,BACK
HERE:SJMP HERE
MOV @R0,#00H
END 

Program to perform maximum of two numbers (8051)

MOV DPTR,#1000H 
MOV R1,#5H
MOV B ,#00H
AGAIN: MOVX A,@DPTR
CJNE A,B ,L1
SJMP L2
L1: JC L2
MOV B,A
INC DPTR
L2: DJNZ R1,AGAIN
END

How to write a Program to swap two variables in 8051 microcontroller.

MOV R0,#00H
MOV A,#01H
MOV B,#05H
MOV R0,B
MOV B,A
MOV A,R0
END 

How to Write a Program to perform 8-bit addition,subtraction,multiplication,division (8051)

MOV  R0,#02H 
MOV  R1,#03H
MOV  R2,#04H
MOV  R3,#05H
MOV  A,R0
ADD  A,R1
MOV  R0,A
MOV A,R2
SUBB  A,R1
MOV  R1,A
MOV  A,R1
MOV  B,R2
MUL  AB
MOV  R2,A
MOV  A,R3
MOV  B,R0
DIV  AB
MOV  R3,A
END