Mzsmunna
10/16/2019 - 8:41 AM

BIBO IN


.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB "Enter Binary: $"
MSG2 DB "Binary Output: $" 
MSG3 DB "Total One: $"
MSG4 DB "Total Zero: $"  
CNT0 DB "0$"
CNT1 DB "0$"
    
.CODE
MAIN PROC
	MOV AX,@DATA
	MOV DS,AX
	
	LEA DX,MSG1
	MOV AH,9
	INT 21H
	
	XOR BX,BX        ; BINARY INPUT
	MOV AH,1
	INT 21H 
	
	WHILE:
	CMP AL,0DH
	JE END_WHILE 
	AND AL,0FH
	SHL BX,1
	OR BL,AL
	INT 21H
	JMP WHILE
END_WHILE:
	MOV AH,2
	MOV DL,0DH
	INT 21H
	MOV DL,0AH
	INT 21H 
	
	LEA DX,MSG2
	MOV AH,9
	INT 21H
    
    MOV CX,16          ; SKIP LEADING ZERO
    WHILE2:
    ROL BX,1
    JNC L1   
    RCR BX,1 
    JMP END_WHILE2
    L1:
    DEC CX
    JMP WHILE2
END_WHILE2:
    
	JCXZ END_FOR      ; OUTPUT 
	MOV AL,30H
	
	FOR:    
	ROL BX,1  
	MOV DL,31H 
	JC INC_CNT1 
	MOV DL,30H
	ADD CNT0,1
	JMP PRINT 
	
	INC_CNT1:
	ADD CNT1,1
	
	PRINT:
	MOV AH,2
	INT 21H
	LOOP FOR  
END_FOR:

	MOV AH,2       
	MOV DL,0DH
	INT 21H
	MOV DL,0AH
	INT 21H 	

	LEA DX,MSG3
	MOV AH,9
	INT 21H 
	
	LEA DX,CNT1
	MOV AH,9
	INT 21H
	       
	MOV AH,2       
	MOV DL,0DH
	INT 21H
	MOV DL,0AH
	INT 21H 
	
	LEA DX,MSG4
	MOV AH,9
	INT 21H
	
	LEA DX,CNT0
	MOV AH,9
	INT 21H 
	 
	MOV AL,0
	MOV AH,4CH
	INT 21H
	MAIN ENDP
END MAIN