## Tuesday, May 31, 2016

### 8051 Program - bcd byte

 ;** Function: bcd_to_byte ;** Purpose: Convert a two-byte BCD into a single byte ;** Input: A = Hi byte to convert (ASCII 0x30-0x39,0x41-0x46) ;** R0 = Lo byte to convert (ASCII 0x30-0x39,0x41-0x46) ;** Output: A = Converted value (binary 0x00-0xFF) ;** Destroyed Registers: None bcd_to_byte: XCH A,R0 SUBB A,#30h JNB ACC.4,bcd_to_byte_2 SUBB A,#07h bcd_to_byte_2: XCH A,R0 SUBB A,#30h JNB ACC.4,bcd_to_byte_3 SUBB A,#07h bcd_to_byte_3: SWAP A ORL A,R0 RET

 ;** Function: byte_to_bcd ;** Purpose: Convert a single byte into two BCD digits ;** Input: A = Byte to convert (0x00-0xFF) ;** Output: A = High nibble (ASCII 0x30-0x39,0x41-0x46) ;** R0 = Low nibble (ASCII 0x30-0x39, 0x41-0x46) ;** Destroyed Registers: None byte_to_bcd: MOV R0,A ANL A,#0Fh ADD A,#0F6h JNC byte_to_bcd_2 ADD A,#07h byte_to_bcd_2: ADD A,#3Ah XCH A,R0 SWAP A ANL A,#0Fh ADD A,#0F6h JNC byte_to_bcd_3 ADD A,#07h byte_to_bcd_3: ADD A,#3Ah RET END

Related topics:
8051 Program - 16 bit hex to bcd   |   8051 Program - 16 bit binary to ascii   |   8051 Program - byte to ascii   |   8051 Program - 5 digit decimal to binary   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051