Here we will see one 8085 program, that program will convert BCD numbers to HEX equivalent.
Problem Statement −
A BCD number is stored at location 802BH. Convert the number into its binary equivalent and store it to the memory location 802CH.
In this problem we are taking a BCD number from the memory and converting it to its binary equivalent. At first we are cutting each nibble of the input. So if the input is 52 (0101 0010) then we can simply cut it by masking the number by 0FH and F0H. When the Higher order nibble is cut, then rotate it to the left four times to transfer it to lower nibble.
Now simply multiply the numbers by using decimal adjust method to get final decimal result.
|8000||31, FF, 80||LXI SP,80FFH||Initialize stack pointer|
|8003||21, 2B, 80||LXI H, 802BH||Pointer to the IN-BUFFER|
|8006||01, 2C, 80||LXI B, 802CH||Pointer to the OUT-BUFFER|
|8009||7E||MOV A, M||Move the contents of 802BH to A|
|800A ||CD, 0F, 80||CALL BCDBIN||Subroutine to convert a BCD number to HEX|
|800D ||02||STAX B||Store Acc to memory location pointed by BC|
|800E||76||HLT||Terminate the program|
|800F ||C5||BCDBIN||PUSH B||Saving B|
|8010||47||MOV B, A||Copy A to B|
|8011||E6, 0F||ANI 0FH||Mask of the most significant four bits|
|8013||4F||MOV C, A||Copy A to C|
|8014||78||MOV A, B||Copy B to A|
|8015||E6, F0||ANI F0H||Mask of the least significant four bits|
|8017||0F||RRC||Rotate accumulator right 4 times|
|801B ||57||MOV D, A||Load the count value to the Reg. D|
|801C ||AF||XRA A||Clear the contents of the accumulator|
|801D ||1E, 0A||MVI E, 0AH||Initialize Reg. E with 0AH|
|801F ||83||SUM||ADD E||Add the contents of Reg. E to A|
|8020||15||DCR D||Decrement the count by 1 until 0 is reached|
|8021||C2, 1F, 80||JNZ SUM|
|8024||81||ADD C||Add the contents of Reg. C to A|
|8025||C1||POP B||Restoring B|
|8026||C9||RET||Returning control to the calling program|