;;PROGRAM FOR CONVERTING HEX TO DECIMAL AND BINARY AUG.27.99 updated 27apr2007
;;HX-DC.COM

K0100:
MOV     SI,82 ;PSP TAIL START
CLD

K0104:

LODSB
CMP     AL,20 ;LEADING SPACES ?
JZ      K0104

DEC     SI
PUSH    SI ;TAIL START
MOV     CX,5

K010E:

LODSB
CMP     AL,0D ;END TAIL ?
JZ      K0151 ;YES

CMP     AL,3F ;SHOW MSSG ?
JZ      K0119 ;YES

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 HX-DC 4C0B [high.low] => 19467 = SYMB = BINARY'

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     SI ;TAIL START
NOP
MOV     CX,4
MOV     BX,1000 ;16^4

K016D:

LODSB ;AL=[DSSI]
MOV     DL,AL
MOV     AH,02 ;PRINT CHAR
INT     21

MOV     DH,00
CMP     DL,3D
JNB     K0180 ;HEX

SUB     DX,+30 ;NUMBER
JMP     018D

K0180:

CMP     DL,5D
JNB     018A  ;LOWER CASE

SUB     DX,+37 ;UPPER CASE A-37=10d
JMP     018D

K018A:

SUB     DX,+57  ;LOWER CASE a-57=10d

K018D:

MOV     AX,DX
MUL     BX
ADD     [K0126],AX ;STORE TAIL VALUE 256^2-1=65535 MAX
MOV     BP,10
MOV     AX,BX
MOV     DX,0
DIV     BP ;10^(n-1)=10^n/10
MOV     BX,AX
LOOP    K016D

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

MOV     DL,3D ;PRINT =
INT     21

MOV     DL,20 ;PRINT SPACE
INT     21

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

MOV     DL,[K0126] ;PRINT LOW CHAR
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

MOV     AX,[K0126]
PUSH    AX ;SAVE TAIL VALUE
MOV     CX,5
MOV     BP,2710 ;=10,000d

K01D7:

MOV     AX,[K0126]
MOV     DX,0
DIV     BP  ;AX=RESULT DX=REMAINDER
PUSH    AX
MOV     DL,AL
MOV     AH,02
ADD     DL,30 ;PRINT CHAR VAL
INT     21

POP     AX
MUL     BP
SUB     [0126],AX ;SUB RESULT
MOV     AX,BP
MOV     BP,A
MOV     DX,0
DIV     BP ;10^(n-1)=10^n/10
MOV     BP,AX
LOOP    K01D7

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

MOV     DL,3D ;PRINT =
INT     21

MOV     DL,20 ;PRINT SPACE
INT     21

POP     BX
MOV     CX,2 ;2 PASSES

K0210:

XCHG    BL,BH
PUSH    CX
MOV     CX,8  ;8 BIT PASSES

K0216:

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

MOV     DL,31 ;CARRY=1
JMP     K0221

MOV     DL,30 ;NO CARRY=0

K0221:

MOV     AH,02 ;PRINT 0/1
INT     21

LOOP    K0216

POP     CX
MOV     DL,2E  ;PRINT .
INT     21

LOOP    K0210  ;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