; multi-segment executable file template.

data segment
    ; add your data here!
     Array dB 000h,07h,045h,025h,015h,07dh,0FEh,0D7h,055H,0f3h,02Dh,080h,0ffh,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00 
     MaxI DB "The Maximum Value in Integer = $"
     Min1 DB "The Minimum Value in Integer = $" 
     ten db 10
     SUM dw 0 
     AVG DB "The Average Value in Integer = $"
     
ends



stack segment
    dw   128  dup(0)
ends

code segment
start:
; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax

    ; add your code here
            
       LEA SI,Array ; offset array to si pointer 
       MOV CL,[si+1] ; size of array 
       MOV Ch,[si] ; size of array
       MOV bL,00 ; initial value of Minimum  
       XOR AX,AX ; fast way to make Register 0
       MOV bH,BYTE PTR[SI] ; initial  value of Maximum 
       LEA DI,sum
       push cx
  L1:
       
          
       
      CMP bL,BYTE PTR[SI] ; compare Minimum to the value of array
      JL L2
      MOV bL,BYTE PTR[SI]  ; make bl Minimum with value of si 
      L2:CMP bH,BYTE PTR[SI]  ;compare Maximum to the value of array
      JG L3
      MOV bH,BYTE PTR[SI] ;make bl  Maximum with value of si 
  L3: 
    inc si
    loop l1
    pop cx    
  ee:
   MOV AX, [SI] ; load value of first array element to ax
   XOR di, di   ; reset bx to use as counter
START1:
   INC di       ; increment bx
   CMP di, CX   ; compare current index with total size
   JGE FINISH   ; go to finish if bx greater than or equals to cx
   ADD AX, [SI + [ 4 * SI]] ; get element at SI + 2*BX (the 2 are size of operand inside array)
   JMP START1    ; loop
FINISH:
   XOR DX, DX   ; reset content of DX (explained below)
   CMP AX, 0    ; test
   JNS UNSIGNED_VAL
   MOV DX, -1   ; set dx to -1
UNSIGNED_VAL:
   IDIV CX      ; divide [DX:
    loop ee
        
                call Average1
               rrr: TEST BH,BH
                Js MaxN
                Call  Maximum ; call and Print  Maximum value of the array
                
                RR:
                TEST bl,BL ;test if bl positive or negative
                js  MinimumNN  
                
                  call Minimum
                  
                   JMP END
                MinimumNN:  call MinimumN  ;  call and Print the  Minimum value and if the value negative go and print negative integer value  
                       JMP END               
                MaxN:Neg BH 
                Call  Maximum
                END:    mov ah,4ch
                int 21h
                Jmp RR
                

            
 MinimumN PROC    NEAR    ;This Procedure To Convert The Hex Value to decimal values
 lea dx,Min1 ; Show The Massage 
 mov ah,9
 int 21h
 xor ax,ax
 xor dx,dx
 xor cx,cx
 mov al,bl         ; To Make The Result of Negative Value of Minimum correct 
 NEG AL   ;
 mov cl,0ah
 div cl
 push ax
 mov ah,00h
 div cl
 push ax
 mov ah,00h
 div cl
 push ax
 mov ax,0200h
 mov dl,"-"
 int 21h
 pop dx
 mov dl,dh
 add dx,30h
 int 21h
 pop dx
 mov dl,dh
 add dx,30h
 int 21h
 pop dx
 mov dl,dh
 add dx,30h
 int 21h
 mov dl,10
 int 21h
 ret
 MinimumN  ENDP 
 
 
                    
      Maximum PROC    NEAR 
      lea dx,MaxI
      mov ah,9           ; This Procedure To Convert The Hex Value to decimal values 
      int 21h 
      xor ax,ax
      xor dx,dx
      xor cx,cx       
      mov al,bh
      mov cl,0ah
      div cl
      push ax
      and ah,00h
      div cl
      push ax
      and ah,00h
      div cl
      push ax
      mov ax,0200h
      pop dx
      mov dl,dh
      add dx,30h
      int 21h
      pop dx
      mov dl,dh
      add dx,30h
      int 21h
      pop dx
      mov dl,dh
      add dx,30h
      int 21h
      mov dl,10
      int 21h
      mov dl,0dh 
      mov ah, 2
      int 21h   
      mov dl,0ah 
      mov ah, 2
      int 21h
      ret
      Maximum ENDP

      
 


Minimum PROC    NEAR    ; If The Minimum Value is positive go here and print the result 

lea dx,Min1
mov ah,9
int 21h
xor ax,ax
xor dx,dx
xor cx,cx          
mov al,bl
mov cl,0ah
div cl
push ax
or ah,00h
div cl
push ax
or ah,00h
div cl
push ax
or ax,0200h
mov dl,"-"
 int 21h
pop dx
mov dl,dh
add dx,30h
int 21h
pop dx
mov dl,dh
add dx,30h
int 21h
pop dx
mov dl,dh
add dx,30h
int 21h
mov dl,10
int 21h    
mov dl,0dh 
mov ah, 2
int 21h   
mov dl,0ah 
mov ah, 2
int 21h
ret
Minimum  ENDP           
 
     
   Average1 PROC    NEAR
   xor ax,ax
   xor dx,dx
    xor cx,cx
    lea dx,AVG
   mov ah,9
   int 21h
      xor dx,dx
      pop ax
      pop dx 
      
     Mov cl,0ah
    div cl
   push ax 

   or ah,00h
   div cl
   push ax
   mov ah,00h
   div cl
   push ax
   mov ax,0200h
   mov dl,"-"
 int 21h
  pop dx
   mov dl,dh
   add dx,30h
   int 21h
   pop dx
   mov dl,dh
   add dx,30h
   int 21h
   pop dx
   mov dl,dh
   add dx,30h
   int 21h
   mov dl,10
   int 21h
   mov dl,0dh 
   mov ah, 2
   int 21h   
   mov dl,0ah 
   mov ah, 2
   int 21h
   jmp RRR 
   ret   
   
   
   end start ; set entry point and stop the assembler.
