TITLE MINMAX  --
;Finds the max and min words in an unordered
;  list in the extra segment
ESEG	SEGMENT
  UNORDLST   DW   50 DUP(?)
  COUNT	     EQU  ($-UNORDLST)/2
ESEG	ENDS
;---------------------------------------------
CSEG	SEGMENT	 PARA 'code'
	ASSUME	 CS:CSEG,ES:ESEG
MINMAX  PROC FAR
	PUSH	DS		;save DS for return	  
	SUB	AX,AX
	PUSH	AX
	MOV	AX,ESEG		;init ES
	MOV	ES,AX

	MOV	CX,COUNT	;get ready for 
	DEC	CX		;  count-1 compares
	LEA	DI,UNORDLST	;address of the list
	MOV	BX,ES:[DI]	;declare it both min
	MOV	AX,BX		;  and max.
CHKMIN:
	ADD	DI,2		;point to next element
	CMP	ES:[DI],BX	;compare element to min
	JAE	CHKMAX		;new minimum found ?
	MOV	BX,ES:[DI]	;yes,put it in BX
	JMP	SHORT NEXTEL
CHKMAX:
	CMP	ES:[DI],AX	;compare element to max
	JBE	NEXTEL		;new max found ?
	MOV	AX,ES:[DI]	;yes,put it in AX
NEXTEL:
	LOOP	CHKMIN		;check entire list ?
	RET			;exit
MINMAX	ENDP
;------------------------------------------
CSEG	ENDS
	END	MINMAX

