Microprocessors exchange data in several codes. Binary (hex) is what the ALU computes with; BCD stores each decimal digit in a nibble; ASCII uses 7-bit codes for characters. Display drivers and keyboards need conversions, so every 8085 kit has standard conversion routines.
BCD-to-hex and hex-to-ASCII conversions| Value | Hex | BCD | ASCII (hex code) |
|---|
| 5 | 05H | 05H | 35H |
| 12 | 0CH | 12H | 31H 32H |
| 255 | FFH | 255H (3 nibbles) | 32H 35H 35H |
; BCD to hex: 2-digit BCD in A -> binary value in A.
MVI B, A ; copy BCD to B
ANI 0F0H ; keep the tens digit only
RRC ; shift right to move tens into low nibble
RRC
RRC
RRC ; now tens digit (0-9) in low nibble
MOV C, A ; C = tens
MOV A, B ; original BCD
ANI 0FH ; keep the units digit
ADD A ; units x 2
MOV B, A ; save units x 2
ADD A ; units x 4
ADD A ; units x 8
ADD B ; units x 10
ADD C ; + tens = full binary value
HLT
; Simpler textbook form:
; BCD value = (tens x 10) + units
; Compute tens x 10 as (tens x 8) + (tens x 2).; Hex digit (0-F) in low nibble of A -> ASCII in A.
; 0-9 -> 30H-39H, A-F -> 41H-46H
ANI 0FH ; mask to one digit
CPI 0AH ; compare with 10
JC NUM ; digit 0-9: add 30H
ADI 37H ; digit A-F: ASCII 'A' is 41H = 0AH + 37H
JMP DONE
NUM: ADI 30H ; ASCII '0' is 30H
DONE: HLT
Input 0AH -> output 41H ('A'); input 07H -> output 37H ('7').