Title kiemtrakitu
.Model Small
.Stack 100h
.Data
 chuoihoa DB 0dh,0ah,'So ki tu hoa la: $'
 chuoithuong DB 0dh,0ah,'So ki tu thuong la: $'
 chuoikhac DB  0dh,0ah,'So ki tu khac la: $'
 chuoisuadoi db 0dh,0ah,'Chuoi chu thuong doi thanh hoa la: $'
 demthuong dw 0
 demhoa dw 0
 demkhac dw 0
 inso dw 0
 chuoi db 128 dup (?)
 
.Code
Main proc
    
    Mov AX,@DATA 
    Mov DS,AX
    Mov ES,AX
    
    Lea di,chuoi
    cld
    
    Lap:           ; Vong lap nhap ky tu
    Mov AH,1       ; Lenh  nhap 1 ky tu
    int 21h
                   
    CMP AL,0Dh     ; So sanh voi ky tu Enter
                   
    JZ ketthuc     ; Neu bang Enter ketthuc
                   
    CMP AL,41h     ; So sanh voi ky tu 'A'
    JB Khac        ; Neu nho hon ky tu A nhay den nhan kiemtraduoi
    
    CMP AL,5Bh     ; Neu k nho hon tiep tuc so sanh voi ky tu '['
    JB ChuHoa      ; Neu nho hon nhay den nhan ChuHoa
                   
    CMP AL,61h     ; Tiep tu kiem tra voi ky tu 'a'
    JB Khac        ; Neu nho hon nhay den nhan khac
    
    CMP AL,7Bh     ; So sanh voi ky tu {
    JB Chuthuong   ; Nho hon nhay den nhan chu thuong
    JAE Khac
    
    
    ChuHoa:        
    INC demhoa     ; Goi thu tuc tt1
    JMP Lap        ; Nhay khong dieu kien den nhan lap
    
    Khac:
    INC demkhac    ; Goi thu tuc tt2
    JMP Lap        ; Nhay khong dieu kien den nhan lap
    
    Chuthuong:
    Xor al,20h     ; Chuyen sang chu hoa
    INC demthuong
    Stosb       
    JMP Lap        ; Nhay khong dieu kien den nhan lap
    

    ketthuc:
    
    mov ah,9
    lea dx,chuoisuadoi
    int 21h
    mov cx,demthuong
    lea si,chuoi
    cld
    LapIn:
       lodsb
       mov dl,al
       mov ah,2
       int 21h
    Loop LapIN   
    
    mov ah,9
    lea dx,chuoithuong
    int 21h
    mov ax,demthuong
    mov inso,ax
    call hienso
    
    mov ah,9
    lea dx,chuoihoa
    int 21h
    mov ax,demhoa
    mov inso,ax
    call hienso
    
    mov ah,9
    lea dx,chuoikhac
    int 21h
    mov ax,demkhac
    mov inso,ax
    call hienso
    
    Mov ah,4Ch
    int 21h
    
Main endp

        hienso proc        

        mov ax, inso        ;dua ket qua trong  bien print ra thanh ghi ax
        mov dx,0            ;xoa bit cao dx
        mov bx,10           ;gan bx=10
        mov cx,0            ;khoi tao bien dem
      chia:        
        div bx              ;lay ket qua chia cho 10
        push dx             ;du o dx day vao ngan xep
        inc cx              ;tang bien dem
        cmp ax,0            ;so sanh thuong voi 0
        je hienkq           ;neu bang thi hien ket qua
        xor dx,dx           ;xoa bit cao trong dx
        jmp chia   
      hienkq:
        pop dx              ;lay du trong ngan xep ra khoi dx
        add dl,30h          ;chuyen so thanh dang ky tu
        mov ah,2            ;in tong
        int 21h
        loop hienkq
        ret
    hienso endp
          
End Main