; The procedure findmin finds the index of the
; minimum value in an array.



IDEAL
MODEL small
STACK 20h
DATASEG

arr1      db     7,3,1,8,2,0
num_elem  equ    6  


CODESEG
; procs here

proc          findmin
; The proc puts the index of the smallest 
; element in ax
              push bp
              mov  bp,sp
              mov  cx,[bp+6]
              mov  bx,[bp+4]
              xor  dx,dx
              mov  dl,[byte ptr bx]
              xor  ax,ax
              mov  si,1
              dec  cx
 loop1:       cmp  dl,[byte ptr bx+si]
              jl   cont
              mov  dl,[byte ptr bx+si]
              mov  ax,si
 cont:        inc  si 
              loop loop1
              pop  bp
              ret  4 
endp          findmin


start:        mov ax, @data
              mov ds, ax

; main code here
              push num_elem
              push offset arr1
              call findmin

exit:         mov ax, 4c00h
              int 21h
END start 