This subroutine converts 12 bit hexadecimal number into its equivalent BCD number. Since the number to be converted is 12 bit total two bytes will be required to represent it. And the converted number will be maximum 4 byte but since the output is in BCD two memory locations will be used to store the final result. The number to be converted is stored in R6 (MSB) & R7 (LSB) whereas the converted BCD number is stored in R0 (MSB) & R1 (LSB). |
|||||||||||||||||||||||||||||||||||
First we work on the HEX LSB (R7) & convert it into BCD as stated in 8-bit HEX to BCD convertor. Then we check if the HEX MSB (R6) is 0 if not zero we add 256 to the BCD & decrement the HEX MSB (R6) until it becomes zero. |
|||||||||||||||||||||||||||||||||||
Hex to BCD: |
|||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||
.