;----------------------------------------------------------
; Assembly program for the min_max function - called from
; the C program in file minmax_c.c. This function finds the
; minimum and maximum of the three integers received by it.
;----------------------------------------------------------
.MODEL SMALL
.CODE
PUBLIC _min_max
_min_max   PROC    
	push    BP
	mov     BP,SP
	; AX keeps minimum number and DX maximum
	mov     AX,[BP+4]    ; get value 1
	mov     DX,[BP+6]    ; get value 2
	cmp     AX,DX        ; value 1 < value 2?
	jl      skip1        ; if so, do nothing
	xchg    AX,DX        ; else, exchange 
skip1:
	mov     CX,[BP+8]    ; get value 3
	cmp     CX,AX        ; value 3 < min in AX?
	jl      new_min
	cmp     CX,DX        ; value 3 < max in DX?
	jl      store_result
	mov     DX,CX
	jmp     store_result
new_min:
	mov     AX,CX
store_result:
	mov     BX,[BP+10]   ; BX := &minimum
	mov     [BX],AX
	mov     BX,[BP+12]   ; BX := &maximum
	mov     [BX],DX
	pop     BP
	ret
_min_max   ENDP
	END
