Mew Prices

LOWER THAN EVER !

above, then type in Listing 2 and merge Sort4 with it (MERGE "SORT4"). Run the merged program. You'll notice a short pause, during which the program sums the data values and checks the total, called a hash total, to make sure it's correct. If not, the program displays an error message.

If the total is correct, the program displays 200 seven-character strings, randomly sequenced, and prompts you to press the enter key to start the sort. In under a second, you'll see the strings redisplayed in sorted alphabetical order.

Routine Matters

Sort4's heart is the machine-language code in data lines 2-5, which is POKEd into the high RAM area you protected from Basic. Although I said earlier that this area started at location 65,304 (FF18 hexadecimal), you don't have to use that address. If, for example, you're already using part of that area for a printer driver, change the 65,304 in line 1 to a lower address. The program automatically handles all relocation.

Remember, however, that SORT4 requires a 232-byte protected memory area, so be sure to change your Basic load command accordingly. If you change line 1 to read S4PTR! = 62000, you should load Basic by typing in BASIC (M = 61999).

Incidentally, the data statements' negative values indicate that the program calculates relocation parameters before it POKEs anything.

Line 14 passes a 4-byte parameter string to the SORT4 machine code. The routine uses the disk-related function MKI$ to store the two integer values most efficiently: as a pointer to the array and a value indicating the number of strings you'U sort.

The array pointer's code in line 14 may seem strange, but it serves a purpose. If you specify a subscript beyond the dimensioned limit, Basic will return an error message, thereby protecting your data in memory from the machine code. ■

You can write to Alan D. Smith at P.O. Box 119, Mortdale, N.S. W. 2223, Australia.

Related Articles

Allan, Ralph C. "Proper Arrangements," June (984, p. 96. Sort multidimensional string arrays under Model III TRSDOS.

deZoysa, C.A. "Graphic Sort," August I960, p. 166. A visual demonstration of the sorting process.

Gonvry, Un. "Ml About Sorts," Pirts \ and U, August 1961, p. 208 and September 1981, p. 148. A tutorial about sorting techniques.

0 0

Post a comment