home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
simtel
/
sigm
/
vols000
/
vol089
/
syslibb.hlp
< prev
next >
Wrap
Text File
|
1985-02-09
|
5KB
|
104 lines
Sort Routines -- Introduction
SSB Initializer
SORT
:Sort Routines -- Introduction
Tw∩á routine≤ arσ provideΣ whicΦ givσ thσ SYSLI┬á programme≥ ì
acces≤á t∩ ß ver∙ flexiblσ sortinτ system«á Thσ maiε routinσá i≤ ì
calleΣá SORT¼á anΣ i⌠ provide≤ ß utilit∙ whicΦ doe≤ aεá in-memor∙ ì
sor⌠á oµá ß se⌠ oµ fixed-lengtΦ records«á Thσ sortinτá techniquσ ì
useΣ i≤ ß Shel∞ Sort¼á adapteΣ froφ thσ booδ "Softwarσ Toolsóá b∙ ì
Kernigaεá anΣ Plaugher¼á publisheΣ b∙ Addison-Wesly¼á 1976¼á pagσ ì
106« Thi≤ sor⌠ i≤ ver∙ fast¼ mucΦ morσ s∩ thaε thσ simplσ bubblσ ì
sort.
Thi≤á Shel∞ Sor⌠ caε bσ donσ iε tw∩ ways║á witΦ o≥á withou⌠ ì
usinτá pointers«á Sortinτá withou⌠ usinτ pointer≤á i≤á typicall∙ ì
slowe≥ thaε sortinτ witΦ pointers¼á anΣ thσ onl∙ advantagσ t∩ no⌠ ì
usinτá pointer≤ i≤ thσ saving≤ oµ spacσ whicΦ i≤ takeε u≡ b∙á thσ ì
pointer≤ (2*numbe≥ oµ entrie≤ bytes)«á Iµ pointer≤ arσ useΣá fo≥ ì
thσá sort¼á theε wheneve≥ aε exchangσ i≤ done¼á thσ pointer≤á arσ ì
simpl∙ exchanged¼á rathe≥ thaε thσ ful∞ records¼ anΣ thi≤ greatl∙ ì
decreases the sort time in most casts.
Thσ SOR╘ routinσ i≤ controlleΣ b∙ passinτ t∩ i⌠ ß pointe≥ t∩ ì
ß Sor⌠ Specificatioε Blocδ (SSB⌐ iε DE«á Thi≤ Sor⌠ Specificatioε ì
Blocδá i≤á ß serie≤ oµ 2-bytσ word≤ whicΦ contaiεá thσá followinτ ì
information:
Bytes 0&1: Starting Address of 1st Record
Bytes 2&3: Number of Records to Sort
Bytes 4&5: Size of Each Record (in Bytes)
Bytes 6&7: Address of Compare Routine Provided by User
Thi≤á routinσ compare≤ tw∩ records¼á onσ ì
ááááááááááááááááááááápointeΣ t∩ b∙ H╠ anΣ thσ othe≥ pointeΣ t∩ b∙ ì
áááááááááááááááááááááDE«á Iµ thσ recorΣ pointeΣ t∩ b∙ D┼ i≤ les≤ ì
áááááááááááááááááááááiε sortinτ orde≥ thaε tha⌠ pointeΣ t∩ b∙ HL¼ ì
áááááááááááááááááááááthi≤ Comparσ Routinσ i≤ t∩ returε witΦ Carr∙ ì
áááááááááááááááááááááSe⌠á (C)«á Iµá thσá record≤á arσá equa∞á iε ì
ááááááááááááááááááááásortinτá order¼á thi≤ Comparσ Routinσ i≤á t∩ ì
áááááááááááááááááááááreturε witΦ Zer∩ Se⌠ (Z)«á Onl∙ thσ PS╫á i≤ ì
áááááááááááááááááááááto be affected by the Compare Routine.
Bytes 8&9: Address of Pointer Table
Bytσ 10║ Flag╗ ░ mean≤ t∩ usσ pointers¼ 0FF╚ mean≤ not
Byte 11: Unused
A≤ mentioneΣ previously¼á tw∩ routine≤ arσ availablσ iε thi≤ ì
sor⌠ module«á Thσ firs⌠ routine¼ SSBINIT¼ look≤ a⌠ thσ beginninτ ì
oµá ßá scratcΦá areßá anΣá thσ initia∞ content≤á oµá aεá SS┬á anΣ ì
allocate≤ spacσ fo≥ thσ pointe≥ table«á I⌠ als∩ check≤ t∩ seσ iµ ì
thσá buffe≥á requireΣ wil∞ overflo≈ thσá TP┴á (Transien⌠á Prograφ ì
Area).
Thσ seconΣ routine¼á SORT¼ perform≤ thσ sort¼ anΣ controlleΣ ì
by the SSB pointer passed to it in DE.
:SSB Initializer
Routine Name: SSBINIT
Function║
Thi≤á routinσ load≤ byte≤ 0&▒ (addres≤ oµ firs⌠ record⌐ ì
anΣá 8&╣ (addres≤ oµ pointe≥ table⌐ oµ aε SSB¼á checkinτ fo≥á TP┴ ì
overflow«á I⌠ i≤ passeΣ thσ star⌠ addres≤ oµ ß scratcΦ area¼ anΣ ì
set≤á thσ pointe≥ tablσ t∩ star⌠ here¼á look≤ a⌠ thσ recorΣá sizσ ì
anΣ recorΣ coun⌠ entrie≤ oµ aε SSB¼á anΣ add≤ thi≤ produc⌠ t∩ thσ ì
addres≤ oµ thσ pointe≥ table«á Thσ resultan⌠ addres≤ i≤ returneΣ ì
as the address of the first record.
Thi≤á routinσá ma∙á bσ useΣ a≤ describeΣá abovσá beforσá an∙ ì
record≤á arσ loadeΣ int∩ memor∙ fo≥ thσ sort¼á o≥ i⌠ ma∙ bσá useΣ ì
afte≥ thσ record≤ havσ alread∙ beeε loaded«á Iε thσ latte≥ case¼ ì
thσá use≥ shoulΣ savσ thσ star⌠ addres≤ oµ thσ firs⌠á recorΣá anΣ ì
cal∞á SSBINI╘á witΦ thσ addres≤ oµ thσ firs⌠ bytσ afte≥ thσá las⌠ ì
record«á Oncσá SSBINI╘á ha≤ loadeΣ thσ buffer≤ iεá thσá SS┬á anΣ ì
checkeΣá fo≥á ßá TP┴á overflo≈ (notσ tha⌠ thi≤ i≤á donσá fo≥á thσ ì
pointer≤ only)¼á i⌠ wil∞ returε t∩ thσ caller¼á a⌠ whicΦ timσ thσ ì
calle≥á shoulΣá restorσ thσ firs⌠ tw∩ byte≤ oµ thσ SS┬á t∩á thei≥ ì
proper values, the actual start address of the first record.
SSBINIT, Con't
Inputs: HL pts to start of scratch area, DE pts to SSB
Outputs: Z Flag is Set (Z) if TPA overflow; NZ if OK
Registers Affected: PSW
SYSLIB Routines Called: MOVEB
Specia∞á Erro≥ Conditions║ None
:SORT
Routine Name: SORT
Function║
SOR╘ sort≤ thσ se⌠ oµ fixeΣ lengtΦ record≤ accordinτ t∩ ì
thσá contro∞á informatioε iε thσ Sor⌠ Specificatioεá Blocδá (SSB⌐ ì
pointed to by DE.
Inputs: DE pts to SSB
Outputs: None (Records are Sorted)
Registers Affected: None
SYSLIB Routines Called: MOVEB, PRINT
Specia∞á Erro≥ Conditions║
Thσ Erro≥ Messagσ "SOR╘ Pointe≥ Erroró ma∙ bσá printed¼ ì
bu⌠ i≤ highl∙ unlikely« Thi≤ indicate≤ ß fla≈ ha≤ developeΣ witΦ ì
thσ SOR╘ routinσ fo≥ thi≤ particula≥ case¼á anΣ i⌠ coulΣ no⌠ SOR╘ ì
thσá se⌠á oµ record≤ a≤ desired«á Thi≤ erro≥ i≤ fata∞á anΣá wil∞ ì
abort to CP/M.