title Timmin
.model small
.stack 100h
.data 
        tb1 db ' Moi ban nhap so phan tu N= $'
	tb2 db 13,10,'So lon nhat la: $'
        tb3 db 13,10,'So be nhat la: $'
        so dw 0
        so1 dw 1
        so2 dw 1
        tong dw 0
        i dw 0
	max dw 0
        min dw 0
        N dw 0
        chuoi dw 5 dup (?)
.code 
    main proc
        mov ax,@data
        mov ds,ax
        mov es,ax
        
        
        lea dx,tb1          
        mov ah,9
        int 21h
        call nhapso
        mov cx,so
        mov n,cx
        lea di,chuoi
        cld
      MoiNhap:
        call nhapso
        mov ax,so
        Stosw
        inc i
        Loop MoiNhap
        
        
        mov cx,n
        sub cx,1
        lea si,chuoi
        lodsw
        mov min,ax
	mov max,ax
        cld
      SoSanh:
        lodsw
        cmp ax,min
        ja sosanh1
        mov min,ax
      sosanh1:
	cmp ax,max
	jb sosanh2
	mov max,ax
      SoSanh2:  
        loop Sosanh
        mov ah,9
	lea dx,tb2
	int 21h
	mov ax,max
	mov tong,ax
	call inso        
        
        mov ah,9
	lea dx,tb3
	int 21h
        mov ax,min
        mov tong,ax
        call inso
        
        
        mov ah,4ch
        int 21h
    Main endp

    nhapso proc
        push cx
        mov ax,0
        mov so,ax
      nhapso1:
        mov ah,1
        int 21h
        cmp al,13         
        je ketthuc1
        CMP AL,'0'
        JB xoakitu
        CMP AL,'9'
        JA xoakitu          
        sub al,30h        
        mov ah,0         
        mov cx,ax       
        mov ax,so      
        mov bx,10       
        mul bx          
        add ax,cx      
        mov so,ax      
        jmp nhapso1
    xoakitu:            

        Mov ah,2        
        mov dl,08h      ; chuyen ki tu backspace vao DL de hien thi
        int 21h

        mov dl,20h      ; chuyen ki tu cach vao hien thi de xoa ki tu khac vua nhap
        int 21h
        
        mov dl,08h
        int 21h
        JMP nhapso1
    ketthuc1:
    pop cx
    mov ah,2
    mov dl,13
    int 21h
    mov dl,10
    int 21h
    ret
    nhapso endp
    
   
    tinhtong proc
                
       mov ax,so1     ;dua bien so 1 ra thanh ghi ax
       mov bx,so2     ;dua bien so 2 ra thanh ghi bx
       add ax,bx             ;caong ax voi bx ket qua cat vao ax
       mov tong,ax         ;dua ket qua tu ax vao bien tong
       ret
    tinhtong endp
    
    inso proc        
        mov ah,9     ;hien thong bao  in tong 
        lea dx,tb3
        int 21h
        mov ax,tong       ;dua ket qua trong  bien tong 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
    inso endp
End main