Thomas N wrote: > What method and how would I do it if I want to do this: > > Before the code is executed, the content of Num1 to Num4 equal: > Num1 = 100 > Num2 = 50 > Num3 = 200 > Num4 = 150 > > After the code is executed, the content of the 4 resulting numbers > are: First_Place = 3 Second_Place = 4 Third_Place = 1 Fourth_Place = 2 > > The content of First_Place is calculated to be 3 to indicate that Num3 > has the highest value. Second_Place equals 4 to indicate that Num4 > has the second highest value. > > I wrote the code for this, it works OK, but it's about 11 pages! So I > think the must be a better way to do this. Thomas: Yes, there is a better way; the most straightforward (although not necessarily the fastest or shortest) would be to have two arrays: Num1-Num4 and Place1-Place4. Put your 100, 50, 200, 150 (or whatever) values in Num1-Num4, then set Place1=1, Place2=2, Place3=3, and Place4=4. Sort Num1-Num4, and every time you swap two of the Numx values, ALSO swap the corresponding Placex values. Here's the bubble-sort code I posted the other day, modified to sort both arrays. The only changes are the additional 4 lines at the end of the ORDER macro and the longer BC branch necessary to accomodate them: ; THIS MACRO COMPARES THE VALUES IN REGISTERS X AND Y. ; IF Y < X, IT SWAPS THEM AND THE CORRESPONDING VALUES ; IN PLACEX AND PLACEY. ORDER MACRO X,Y MOVF X,W ;GRAB X. SUBWF Y,W ;Y >= X? BC $+7 ;IF SO, JUMP AHEAD. ADDWF X ;OTHERWISE, X = X + (Y-X) = Y, SUBWF Y ; AND Y = Y - (Y-X) = X. MOVF PLACE1+(X-NUM1),W ;SWAP PLACEx AND PLACEy. XORWF PLACE1+(Y-NUM1),W ; XORWF PLACE1+(X-NUM1) ; XORWF PLACE1+(Y-NUM1) ; ENDM ; SORT NUM1-NUM4 IN ASCENDING ORDER. SORTSUB: CALL SORT3 CALL SORT2 SORT1: ORDER NUM1,NUM2 SORT2: ORDER NUM2,NUM3 SORT3: ORDER NUM3,NUM4 RETURN -Andy === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - San Diego, California === http://www.geocities.com/SiliconValley/2499 -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body