## Saturday, April 30, 2016

### 8051 Program – hex to bcd 8bit

``` ; 8bit hex to bcd conversion ; input: 4000H ; output: 4001H - 4002H ORG 0H HEX_ADDR EQU 4000H MAIN: MOV DPTR,#HEX_ADDR ; fill memory MOV A, #1fH MOVX @DPTR,A LCALL CONV SJMP MAIN CONV: MOV DPTR,#HEX_ADDR MOVX A,@DPTR MOV B,#64H ; divide by 100 DIV AB INC DPTR MOVX @DPTR,A MOV A,B MOV B,#0AH ; divide by 10 DIV AB SWAP A ADD A,B INC DPTR MOVX @DPTR,A RET END ```

Steps:
Find number of 100’s in the given number and store it in memory.
Find number of 10’s from remainder and store it in memory.
Find number of 1’s from remainder and store it in memory.

START
GET DATA CARRY =0, HUNDREDS =0, TENS=0
DATA =DATA -100
IS CARRY =1 ?. if no, HUNDREDS =HUNDREDS + 1 and go to above.
If yes, DATA = DATA + 100
DATA = DATA – 10
IS CARRY =1 ?. if no, TENS =TENS + 1 go to above.
If yes, DATA = DATA – 10
UNITS =DATA
STORE HUNDREDS ,TENS , UNITS
STOP

Related topics:
8051 Program - decimal to hex   |   8051 Program - hex to decimal 8bit   |   8051 Program - decimal to ascii   |   8051 Program - ascii to decimal   |   8051 Program - hex to ascii   |   8051 Program - ascii to hex   |   8051 Program - bcd to ascii   |   8051 Program - ascii to bcd   |   8051 Program - bcd to hex 8bit   |   8051 Program - hex to bcd 12bit   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051