Title ChuanHoa
.Model Small
.Stack 100h
.Data
    chuoi1 db 'Nhap chuoi: ',10,13,'$'
    chuoi2 db 10,13,'Ket qua:',10,13,'$'
    chuoi3 db 10,13,'Ket qua nhi phan:',10,13,'$'
    chuoi db 128 dup (?)
    kq db 128 dup (?)
    i dw 0
    dem1 dw 0
    dem dw 0
    thu db ?

.Code
    Main proc
        Mov ax,@data
        Mov ds,ax
        mov es,ax
        mov ah,9
        lea dx,chuoi1
        int 21h
        lea DI,chuoi
    
    LapNhap:
        mov ah,1
        int 21h
        cmp al,0dh
        je kt
        stosb
        Inc i
        cmp i,128
        je kt
        jmp LapNhap        
    kt: 
        mov ah,9
        lea dx,chuoi2
        int 21h
        cmp i,0
        je xong
        lea SI,chuoi
        lea di,kq
        mov cx,i
    kt1:    
        lodsb
        cmp al,20h
        je het
        stosb
        inc dem1
        mov dl,al
        mov ah,2
        int 21h
        loop kt2
        jmp xong
    kt2:
        lodsb
        cmp al,20h
        je xong
        stosb
        inc dem1
        mov dl,al
        mov ah,2
        int 21h
        loop kt2
        jmp xong        
    het:    
        loop kt1

    xong:
        mov ah,9
        lea dx,chuoi3
        int 21h
        mov cx,dem1
        lea si,kq
        cld
        AA:
        lodsb
        call innhiphan
        mov ah,2
        mov dl,20h
        int 21h
        loop AA    
        mov ah,4ch
        int 21h
 main ENDP    

innhiphan proc
         push cx
         push ax
         push dx
         push bx
         
         mov bl,al
          
         
         MOv CX,8  
         mov ah,2
        innhiphan1:
         shl bl,1  
         JC In1
         mov dl,'0'
         int 21h
          
         jmp Lap 
         In1:
         Mov dl,'1'
         int 21h
         
         Lap:
         Loop Innhiphan1
         
         pop bx
         pop dx
         pop ax
         pop cx
         ret
         innhiphan endp  
END Main        

