Mzsmunna
10/16/2019 - 8:45 AM

binary_inPut_OUTPUT_counting)and1


.MODEL SMALL
.STACK 100H
.DATA

MSG1 DB 'Enter Binary :$'
MSG2 DB 'BinaryIs :$' 
MSG3 DB 'Total-1 :$'
MSG4 DB 'Total-0 :$'  


TOTAL1 DB 0
TOTAL0 DB 0 
COUNT DB 0
DECIMAL DB 0
 
.CODE

MAIN PROC 
    
    MOV AX,@DATA
    MOV DS,AX
 
    XOR BX,BX
    MOV CL,1 
    
    LEA DX,MSG1
    MOV AH,9
    INT 21H
 
    TOP:
       MOV AH,1
       INT 21H
     
       CMP AL,0DH
       JE END_
     
       AND AL,0FH         
     
       SHL BX,1
       OR BL,AL

       JMP TOP
     
    END_:  
 
    MOV AH,2
    MOV DL,0AH
    INT 21H
    MOV DL,0DH
    INT 21H
    
    LEA DX,MSG2
    MOV AH,9
    INT 21H
 
    MOV CL,1
    MOV CH,0
    OUTPUT:
          CMP CH,16
          JE FINISH
          INC CH
          SHL BX,CL
          JC ONE
       
       
          MOV AH,2
          MOV DL,30H
          INT 21H
          INC TOTAL0
          JMP OUTPUT
       
    ONE:
        MOV AH,2
        MOV DL,31H
        INT 21H
        INC TOTAL1
      
        
        
        
        JMP OUTPUT
 
    FINISH:
    MOV AH,2
    MOV DL,0AH
    INT 21H
    MOV DL,0DH
    INT 21H
    
    LEA DX,MSG3
    MOV AH,9
    INT 21H
    ADD TOTAL1,48
    CMP TOTAL1,57
    JG  L0: 
    
    MOV DL,TOTAL1
    
    MOV AH,2
    INT 21H
    JMP T 
    
    L0:
    MOV DL,'1'
    MOV AH,2
    INT 21H
    CMP TOTAL1,58
    JE  L1
    CMP TOTAL1,59
    JE  L2
    CMP TOTAL1,60
    JE  L3
    CMP TOTAL1,61
    JE  L4
    
    CMP TOTAL1,62
    JE  L5
    CMP TOTAL1,63
    JE  L6
    
    CMP TOTAL1,64
    JE  L7
    
    L1: MOV DL,'0'
        MOV AH,2
        INT 21H
        JMP T
    L2: MOV DL,'1'
        MOV AH,2
        INT 21H
        JMP T
    L3: MOV DL,'2'
        MOV AH,2
        INT 21H
        JMP T
    L4: MOV DL,'3'
        MOV AH,2
        INT 21H 
        JMP T
     
     
    
    L5: MOV DL,'4'
        MOV AH,2
        INT 21H 
        JMP T
    L6: MOV DL,'5'
        MOV AH,2
        INT 21H
        JMP T
    L7: MOV DL,'6'
        MOV AH,2
        INT 21H
        JMP T
   
    
    T:        
           
    MOV AH,2
    MOV DL,0AH
    INT 21H
    MOV DL,0DH
    INT 21H
    
    LEA DX,MSG4
    MOV AH,9
    INT 21H 
    ADD TOTAL0,48
    CMP TOTAL0,57
    JG  SO:
    
    MOV DL,TOTAL0
    
    MOV AH,2
    INT 21H 
    JMP S8
    
    SO:
    MOV DL,'1'
    MOV AH,2
    INT 21H
    CMP TOTAL0,58
    JE  S1
    CMP TOTAL0,59
    JE  S2
    CMP TOTAL0,60
    JE  S3
    CMP TOTAL0,61
    JE  S4
    
    CMP TOTAL0,62
    JE  S5
    CMP TOTAL0,63
    JE  S6
    
    CMP TOTAL0,64
    JE  S7
    
    
    S1: MOV DL,'0'
        MOV AH,2
        INT 21H
        JMP S8
    S2: MOV DL,'1'
        MOV AH,2
        INT 21H
        JMP S8
    S3: MOV DL,'2'
        MOV AH,2
        INT 21H
        JMP S8
    S4: MOV DL,'3'
        MOV AH,2
        INT 21H
     
        JMP S8
    
    S5: MOV DL,'4'
        MOV AH,2
        INT 21H
        JMP S8
    S6: MOV DL,'5'
        MOV AH,2
        INT 21H
        JMP S8
    S7: MOV DL,'6'
        MOV AH,2
        INT 21H
        JMP S8
        
    S8:    
      
    MOV AH,4CH
    INT 21H
           
   
    MAIN ENDP
END MAIN