;;; PROGRAM TO CONVERT DECIMAL TO HEX  AUG.27/99 updated 27apr2007

;;; DC-HX.COM

K0100:
MOV     SI,82 ;PSP TAIL START
CLD

K0104:

LODSB
CMP     AL,20 ;LEADING SPACES ?
JZ      K0104

DEC     SI
PUSH    SI ;SAVE TAIL START
MOV     CX,6
LODSB
CMP     AL,0D ;END IF TAIL
JZ      K0151

CMP     AL,3F ;SHOW MSSG ?
JZ      K0119

LOOP    K010E

K0119:

MOV     DX,K0128
MOV     AX,900   ;PRINT MSSG
INT     21

K0121:

MOV     AX,4C00 ;RETURN TO DOS
INT     21

K0126:  DB 0

K0127:  DB 0

K0128: DB 0D, 0A, 'Try DC-HX 19467 => 4C0B [high.low] = SYMB = DECIMAL = BINARY ;MSSG'

K0151:

MOV     AH,02
MOV     DL,0A
INT     21

MOV     DL,0D ;PRINT NEWLINE
INT     21

DEC     SI
MOV     BYTE PTR [SI],24 ;POKE $ -FOR AH 9
MOV     WORD PTR [K0126],0 ;RESET
POP     DX ;TAIL START
PUSH    DX
MOV     AH,9 ;PRINT TAIL
INT     21

MOV     DL,20 ;PRINT SPACE
MOV     AH,02
INT     21

MOV     DL,3D ;PRINT
INT     21

MOV     DL,20 ;PRINT SPACE
INT     21

POP     DI ;TAIL START
NOP
DEC     SI ;END OF TAIL
MOV     CX,SI
SUB     CX,DI
INC     CX ;LENGTH OF TAIL
MOV     WORD PTR [K0126],0
STD
MOV     BP,1

K018B:

LODSB ;AL=[DSSI]
MOV     AH,00
SUB     AL,30 ;CONVERT TO DECIMAL
MOV     DX,0000
MUL     BP
ADD     [K0126],AX ;ADD
MOV     AX,BP
MOV     DX,0000
MOV     BP,000A
MUL     BP ;10^(n+1)=10^n x 10
MOV     BP,AX
LOOP    K018B

MOV     DL,[K0127] ;PRINT HIGH
MOV     AH,02
INT     21

MOV     DL,[K0126] ;PRINT LOW
INT     21

MOV     DL,20 ;PRINT SPACE
INT     21

MOV     DL,3D ;PRINT =

INT     21

MOV     DL,20 ;PRINT SPACE
INT     21

MOV     AX,[K0126]
PUSH    AX  ;STORE VALUE
MOV     BP,1000 ;=16^4
MOV     CX,4

K01CB:

MOV     AX,[K0126]
MOV     DX,0
DIV     BP  ;AX=RESULT DX=REMAINDER
MOV     [K0126],DX
CMP     AL,0A
JNB     K01DF

ADD     AL,30  ;NUMBER
JMP     K01E1

K01DF:

ADD     AL,37 ;HEX A/B/C/D/E/F

K01E1:

MOV     DL,AL ;PRINT CHAR
MOV     AH,02
INT     21

MOV     AX,BP
MOV     DX,0000
MOV     BP,0010
DIV     BP  ;16^(n-1)=16^n/16
MOV     BP,AX
LOOP    K01CB ;PRINT 4 CHAR

MOV     DL,20 ;PRINT SPACE
MOV     AH,02
INT     21

MOV     DL,3D ;PRINT =

INT     21

MOV     DL,20 ;PRINT SPACE
INT     21

POP     BX  ;RESTORE VALUE
MOV     CX,2 ;2 PASS HICH/LOW

K0207:

XCHG    BL,BH
PUSH    CX ;SAVE COUNTER
MOV     CX,8  ;8 PASSES=BITS

K020D:

CLC ;CLEAR CARRY
ROL     BL,1 ;ROTATE LEFT INTO CARRY
JNB     K0216

MOV     DL,31 ;CARRY=1
JMP     K0218

K0216:

MOV     DL,30 ;NO CARRY=0

K0218:

MOV     AH,02 ;PRINT 1/0
INT     21

LOOP    K020D

POP     CX
MOV     DL,2E ;PRINT .

INT     21

LOOP    K0207  ;NEXT 8 BITS

JMP     K0121 ;DONE RET TO DOS


UPDATED DISPLAY

Would you like to order my
'Machine Code Training For The IBM-PC Using Debug.Exe'
which contains a complete desciption, with comments,
of all updated Chess COM programs and other COM programs.
Contact Louie.Pace@Xlibris.com at Xlibris.com.
(refer your order to BID 38633)


1