- 2069 Bhadra · 8 marks
8085 ALP: BCD to binary conversion
Short answer
Extract the high nibble (AND F0H, rotate right 4 times), multiply by 10 using additions (×2, ×4, ×5, then ×2 to get ×10). Add the low nibble obtained via ANI 0FH. Convert ten bytes from 4350H; e.g., 47H becomes 2FH.
Write a program to convert ten BCD numbers stored at 4350H to binary and store the result at 4360H.
Each packed BCD byte holds two decimal digits, so binary value = (high digit × 10) + low digit. The high digit is isolated, multiplied by 10 using shifts-and-adds (×10 = ×4 + ×1, then ×2), and added to the low digit.
Algorithm
- HL → source (4350H), DE → destination (4360H), C = 10 (count).
- Take the byte, mask the upper nibble (F0H) and rotate right four times to bring it to the lower nibble.
- Multiply by 10: A×2 → A×4, add original (A×5), double (A×10).
- Add the lower nibble (byte AND 0FH). Store the result and advance the pointers.
LXI H,4350H ; HL = source address of BCD numbers
LXI D,4360H ; DE = destination address
MVI C,0AH ; counter = 10 numbers
NEXT: MOV A,M ; A = packed BCD byte
ANI 0F0H ; keep high digit only
RRC ; rotate right 4 times -> high digit in
RRC ; the lower nibble
RRC
RRC
MOV B,A ; B = high digit (x)
ADD A ; A = 2x
ADD A ; A = 4x
ADD B ; A = 5x
ADD A ; A = 10x
MOV B,A ; B = 10 x high digit
MOV A,M ; get the byte again
ANI 0FH ; A = low digit
ADD B ; A = 10 x high + low = binary
STAX D ; store binary result
INX H ; next BCD number
INX D ; next destination
DCR C ; one number done
JNZ NEXT ; repeat until all ten are converted
HLT
Example: BCD 47H → high digit 4 → 40 (28H); low digit 7; result 28H + 07H = 2FH (47 decimal). BCD 99H → 63H.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- 8085 ALP: square of ten numbers · Microprocessor, chapter 2
- 8085 ALP: count ones in upper nibble · Microprocessor, chapter 2
- 8085 ALP: add upper and lower nibbles · Microprocessor, chapter 2
- 8085 ALP: multiplication table of a number · Microprocessor, chapter 2
- 8085 ALP: divide two bytes · Microprocessor, chapter 2
- 8085 ALP: compare two tables of 16-bit data · Microprocessor, chapter 2
- C program: sum of two 8-bit BCD numbers · Embedded System, chapter 9
- Protected specifier; student/test/result program · Object Oriented Programming, chapter 6
- Greatest and smallest of ten numbers · Computer Programming, chapter 11
- Short note: Stored program control · Telecommunications, chapter 4