Mzsmunna
10/16/2019 - 9:03 AM

HEX to BIN-2


.MODEL SMALL
.STACK 100H
.DATA
M1 DB 'ENTER HEX:$'
M2 DB 'HEX IS:$'
ONE DB 0
ZERO DB 0
.CODE
MAIN PROC
    MOV AX,@DATA
    MOV DS,AX
    
    LEA DX,M1
    MOV AH,9
    INT 21H
    
    XOR BX,BX
    XOR CX,CX
    
    MOV CL,4
    MOV AH,1
    INT 21H
    
    L1:
    CMP AL,0DH
    JE PR1
    
    CMP AL,39H
    JG LETTER
    
    AND AL,0FH
    JMP SHIFT
    
    LETTER:
    SUB AL,37H
    
    SHIFT:
    SHL BX,CL
    
    OR BL,AL
    INT 21H
    JMP L1
    
    
    PR1:
    MOV CX,CX
    MOV CX,16
    MOV AH,2
    MOV DL,0DH
    INT 21H
    MOV DL,0AH
    INT 21H 
    
    LEA DX,M2
    MOV AH,9
    INT 21H
    
    PRB:
     ROL BX,1
     JC PRONE
     
     CMP ONE,0
     JG PRZERO
     
     LOOP PRB
     
     JMP EXT
     
    PRONE:
     MOV AH,2 
     MOV DL,'1'
     INT 21H
     
     INC ONE 
     DEC CX
     JCXZ EXT
     JMP PRB 
     
     PRZERO:
     MOV AH,2
     MOV DL,'0'
     INT 21H
     DEC CX
     JCXZ EXT
     JMP PRB
     
     EXT:
     MOV AH,4CH
     INT 21H
     MAIN ENDP
END MAIN