Sunday, September 13, 2009

HEX to Decimal conversion (8085)

Statement: Convert the HEX number in memory to its equivalent decimal number

Source Program:
LXI H, 4150 ; Point to data
LXI B, 0000 ; Initialize hundreds= 0, Tens=0
MOV A, M ; Get hex data to A
LOOP: SUI 64
JC LOOP 1
INR B ; hundreds= hundreds+1
JMP LOOP
LOOP 1: ADI 64 ; if subtracted extra, add it clear carry flag
LOOP 2: SUI 0A
JC LOOP 3
INR C ; Tens=tens+1
JMP LOOP 2
LOOP 3: ADI 0A ; If subtracted extra, add it again
INX H ; A = Units
MOV M, B ; store hundreds
MOV B, A ; Combine Tens in C &
MOV A, C ; Units in A to form a
RLC ; Single 8-bit number
RLC
RLC
RLC
ADD B
INX H
MOV M, A ; Store tens & Units
HLT

No comments:

Post a Comment