8051 assembly language

Status
Not open for further replies.

synckewl

New Member
Dear guys, I have just started learning 8051 assembly language. Can anybody explain what does the following coding do? The program supposed to convert hex to 2 digit BCD and both digits will be displayed on a 2 digit LED.

I still don't understand the flow of this program after staring at it for 2 hrs. Thanks in advance
////////////////////////////////////////////////////////////
Hex2BCD:

MOV R3,#0
MOV R4,#0
MOV R5,#0
MOV R6,#0
MOV R7,#0


MOV B,#10
MOV A,R2
DIV AB
MOV R3,B ;
MOV B,#10 ; R7,R6,R5,R4,R3
DIV AB
MOV R4,B
MOV R5,A
CJNE R1,#0H,HIGH_BYTE ; CHECK FOR HIGH BYTE
SJMP ENDD

HIGH_BYTE:
MOV A,#6
ADD A,R3
MOV B,#10
DIV AB
MOV R3,B
ADD A,#5
ADD A,R4
MOV B,#10
DIV AB
MOV R4,B
ADD A,#2
ADD A,R5
MOV B,#10
DIV AB
MOV R5,B
CJNE R6,#00,ADD_IT
SJMP CONTINUE
ADD_IT:
ADD A,R6
CONTINUE:
MOV R6,A
DJNZ R1,HIGH_BYTE
MOV B, #10
MOV A,R6
DIV AB
MOV R6,B
MOV R7,A

ENDD: ret
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…