## Saturday, April 30, 2016

### 8051 Program – bcd to hex 8bit

``` ; bcd to hex conversion ; input: 4000H ; output: 4001H ORG 0H BCD_ADDR EQU 4000H MAIN: MOV A, #ASCII_1 ; fill memory with ascii MOV DPTR,#BCD_ADDR ; fill memory MOV A, #15H MOVX @DPTR,A LCALL CONV SJMP MAIN CONV: MOV DPTR,#BCD_ADDR MOVX A,@DPTR MOV R5,A ANL A,#0F0H SWAP A MOV R1,A MOV A,R5 ANL A,#0FH MOV R2,A MOV A,R1 MOV B,#0AH MUL AB ADD A,R2 INC DPTR MOVX @DPTR,A RET END ```

Steps:
Separate the given 8bit packed bcd number in to two 4bit unpacked bcd nibbles (bcd1 and bcd2)
Multiply bcd2 with 10

START
GET MOST SIGNIFICANT DIGIT (MSD)
MSD = MSD x 10
HEX DATA = MSD + LSD (LEAST SIGNIFICANT DIGIT)
STORE HEX DATA
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 - hex to bcd 8bit   |   8051 Program - hex to bcd 12bit   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051