.TITLE SortProcedure ; Procedure to sort an array of records in descending order ; according to the contents of the average field ; Argument list: ; Parameter offset purpose data type passed by Number = 4 ; Number of records longword reference Team = 8 ; Records for team array of reference ; members records ; Other constants: Length = 7 ; Number of fields (longwords) in record Ave = 6 ; The number of the field containing average .SHOW MEB ; * * * * * * * * * * * * * .MACRO MoveRecord From, FromSub=#0, - To, ToSub=#0, ?Loop ; Copies a record with Length bytes from ; From[FromSub] to To[ToSub]. ; Get address of From[FromSub] MULL3 #Length, FromSub, R0 ; R0 <-- longwords before From[FromSub] MOVAL From[R0], R1 ; R1 <-- address of From[FromSub] ; Get address of To[ToSub] MULL3 #Length, ToSub, R0 ; R0 <-- longwords before To[ToSub] MOVAL To[R0], R2 ; R2 <-- base address To[ToSub] ; Move the longwords MOVL #Length, R0 ; Put counter in R0 Loop: MOVL (R1)+, (R2)+ ; Move next longword SOBGTR R0, Loop ; Decrement counter and repeat, ; if needed .ENDM MoveRecord ; * * * * * * * * * * * * * .MACRO CompareField AddressTeam = R3 ; Compares the SortField in Team[J] to the corresponding field in Temp. ; Get address of field in Team MULL3 #Length, J, R0 ; R0 <-- longwords before Team[J] ; Compare fields CMPL 4*Ave(R3)[R0], 4*Ave+Temp ; Set condition flags .ENDM CompareField ; * * * * * * * * * * * * * ; Local storage: .PSECT LocalVar NOEXE, WRT I: .BLKL 1 ; Outer loop counter J: .BLKL 1 ; Inner loop counter JPlus1: .BLKL 1 ; J + 1 Temp: ; Save room for a record of .BLKL 12 ; up 12 longwords ; Register usage: ; R0-R2 temporary storage in macros ; R3 address of Team ; * * * * * * * * * * * * * .PSECT ProcCode EXE, NOWRT .ENTRY SortTeam ^M Start: ; Initialize MOVL Team(AP), R3 ; R3 <-- address of Team MOVL #1, I ; I <-- 1 OuterLoop: ; Put record Team[I+1] in proper place CMPL I, @Number(AP) ; If I >= Number BLSS L1 ; then BRW Done ; the list is in order L1: MoveRecord From=(R3), FromSub=I - ; Temp <-- Team[I] To=Temp SUBL3 #1, I, J ; J <-- I - 1 InnerLoop: ; Find the correct place for Temp ADDL3 #1, J, JPlus1 ; JPlus1 <-- J + 1 BEQL Insert ; If JPlus1 = 0, insert Temp CompareField BGEQ Insert ; Branch if location found MoveRecord From=(R3), FromSub=J, -; Team[J+1] <-- Team[J] To=(R3), ToSub=JPlus1 DECL J ; Decrement J BRB InnerLoop ; Repeat inner loop Insert: ; Insert Temp into proper place MoveRecord From=Temp, - ; Team[J+1] <-- Temp To=(R3), ToSub=JPlus1 INCL I ; Increment outer loop counter BRW OuterLoop Done: ; Return RET .END