; ********** BINARY TO DECIMAL CONVERSION SUBROUTINE ********** ; CONVERTS UP TO 6 ASCII CHARACTERS REPRESENTING ; DECIMAL NUMBERS TO BINARY. MAXIMUM VALUE IS 65535. ; ENTRY: (HL) = 16-BIT BINARY VALUE. ; (IX) = POINTER TO START OF CHARACTER BUFFER. ; EXIT: (BUFFER) = FILLED WITH 5 ASCII CHARACTERS WITH LEADING ZEROES. ; (IX+ = BUFFER + 5. ; ************************************************************* .org 0000h LD SP, 00FEh ; ADDED FOR TESTING PURPOSES. LD IY, 0060h ; ADDED FOR TESTING PURPOSES. LD IX, 0050h ; ADDED FOR TESTING PURPOSES. LD HL, 1234h ; ADDED FOR TESTING PURPOSES. ; LD B, 05h ; ADDED FOR TESTING PURPOSES. ; LD C, 00h ; ADDED FOR TESTING PURPOSES. CALL BINDEC ; ADDED FOR TESTING PURPOSES. HALT ; ADDED FOR TESTING PURPOSES. BINDEC: LD IY, PTABLE ; POWER OF 10 TABLE. BIN010: XOR A ; DIGIT COUNT TO 0. LD D, (IY +1) ; GET MOST SIGNIFICANT BYTE. LD E, (IY +0) ; GET LEAST SIGNIFICANT BYTE. BIN020: OR A ; CLEAR CARRY FLAG. SBC HL, DE ; SUBTRACT POWER OF 10. JP C, BIN030 ; GO IF NEGATIVE. INC A ; BUMP DIGIT COUNT. JP BIN020 ; CONTINUE. BIN030: ADD HL, DE ; RESTORE TO POSITIVE. ADD A, 30h ; CONVERT TO ASCII. LD (IX +0), A ; STORE IN BUFFER. INC IX ; BUMP BUFFER POINTER. INC IY ; BUMP POWER 10 POINTER. INC IY LD A, E ; GET LEAST SIGNIFICANT BYTE. CP 1 ; TEST FOR 5 DIGITS. JP NZ, BIN010 ; GO IF NOT 5 DIGITS. RET ; RETURN. .ORG 0060h PTABLE: .DW 10000 ; 2710h. .DW 1000 ; 03E8h. .DW 100 ; 0064h. .DW 10 ; 000Ah. .DW 1 ; 0001h. .END