(C) 1998 AROS - The Amiga Research OS
QSort is an implementation of Hoares sorting algorithm. It uses a constant amount of stack no matter what the size of the file.
return = user_function(el1, el2) d0 a0 a1
Your function must return the following in D0:
if (el1 < el2) return < 0 if (el1 > el2) return > 0 if (el1 == el2) return = 0
You must save all registers except a0, a1, d0, d1. (See below for an example of a C calling sequence)
QSort will also pass A5 to you unchanged. You can use this register to point to pass information to your comparison routine.
RETURNS -1 if everything is cool, 0 if there was an internal recursion stack overflow (not too likely).
EXAMPLE: Here is an example of a calling sequence from C, which is to sort an array of pointers to strings:
char **names; long numEls; extern Cmp();
if (QSort(names, numELs, 4L, Cmp)) do whatever else STACK_ERROR
the Cmp function would look like this:
Cmp() { { #asm public _geta4 movem.l d2-d3/a4/a6,-(sp) ; save important registers movem.l a0/a1,-(sp) ; push args bsr _geta4 bsr _cmp ; call real compare function addq.l #8,sp ; clean up args movem.l (sp)+,d2-d3/a4/a6 ; restore registers #endasm } }
The cmp function called by the above is a normal C function, it can be whatever you like. Here is a sample one:
cmp(s1,s2) char **s1, **s2; { return strcmp(*a, *b); }