!**********************************************************************
TITLE 'TDSORTR - PC/370 4.2 RECURSIVE SORT// DELIA'
***********************************************************************
* *
* MODULE: TDSORTR. *
* AUTHOR: TONY DELIA. *
* DATE: 09/25/96. *
* DESC: PC/370 4.2 - RECURSIVE SORT. *
* NOTE: PC/370 RELEASE 4.2 *
* *
***********************************************************************
EJECT
***********************************************************************
* T D S O R T R P R O G R A M *
***********************************************************************
TDSORTR START 0 START PROGRAM
STM 14,12,12(13) SAVE REGISTERS
LR 12,15 LOAD PROGRAM ENTRY POINT
USING TDSORTR+0*4096,12 BASE REGISTER 1
L 11,BASE2 LOAD BASE REGISTER 2
USING TDSORTR+1*4096,11 TELL ASSEMBLER ABOUT BASE2
ST 13,SAVE+4 SAVE EXTERNAL SAVE ADDRESS
LR 14,13 XFER ADDRESS TO TEMP R14
LA 13,SAVE LOAD INTERNAL SAVE ADDRESS
ST 13,8(14) SAVE IN EXTERNAL SAVE AREA
B GO BRANCH TO PROCESSING RTN
***********************************************************************
RETURN EQU * TIME TO RETURN
L 13,SAVE+4 RESTORE REGISTER 13
LM 14,12,12(13) RESTORE REMAINING REGS
SR 15,15 CLEAR RETURN CODE
BR 14 BRANCH TO CALLING PROGRAM
***********************************************************************
SAVE DC 18F'0' S A V E A R E A
***********************************************************************
BASE2 DC A(TDSORTR+1*4096) BASE2 DISPLACEMENT
***********************************************************************
GO EQU * BEGIN PROCESSING ...
***********************************************************************
EJECT
***********************************************************************
* MAINLINE PROCEDURE *
***********************************************************************
PRINT NOGEN
LA 2,=C'BEFORE SORT <enter>$' LOAD FIELD ADDRESS
SVC @WTO ISSUE SUPERVISOR CALL
SVC @RDKEY ISSUE SUPERVISOR CALL
STC 0,KEY STORE KEYSTROKE
*
LA 3,RSTACK-12 LOAD STACK ADDRESS - 12
LA 4,RTAB LOAD TABLE LO ADDRESS
LA 5,RTABX-L'RENTRY LOAD TABLE HI ADDRESS
BAL 6,RSORT EXECUTE RECURSIVE SORT
*
BAL 6,TRACE PRINT TRACE FILE
*
LA 2,=C'AFTER SORT <enter>$' LOAD FIELD ADDRESS
SVC @WTO ISSUE SUPERVISOR CALL
SVC @RDKEY ISSUE SUPERVISOR CALL
STC 0,KEY STORE KEYSTROKE
B RETURN EXIT PROGRAM PLEASE
***********************************************************************
EJECT
***********************************************************************
* RECURSIVE SORT R3=STACK R4=LO R5=HI *
***********************************************************************
CNOP 0,4 FULLWORD ALIGNMENT
RSORT EQU *
LA 3,12(,3) INCREMENT STACK POINTER
ST 6,0(3) SAVE RETURN ADDRESS
*
CR 4,5 LO ADDRESS >= HI ADDRESS
BNL RSORTX YES - EXIT RSORT
*
LR 6,4 LOAD FWD POINTER
LA 7,L'RENTRY(,5) LOAD BWD POINTER
MVC RKEY,0(4) LOAD SORT OBJECT
RFWD EQU *
LA 6,L'RENTRY(,6) INCREMENT FWD POINTER
CR 6,7 FWD/BWD BOUNDARY CROSS?
BH *+14 YES - TRAVERSE BACKWARDS
CLC RKEY,0(6) KEY LESS THAN OBJECT?
BNL RFWD NO - REPEAT FWD LOOP
RBWD EQU *
SH 7,=Y(L'RENTRY) DECREMENT BWD POINTER
CR 6,7 FWD/BWD BOUNDARY CROSS?
BH RDONE YES - MAKE PRIMARY SWAP
CLC RKEY,0(7) KEY MORE THAN OBJECT?
BNH RBWD NO - REPEAT BWD LOOP
*
XC 0(L'RENTRY,6),0(7) ISOLATE UNIQUE BITS
XC 0(L'RENTRY,7),0(6) REPLACE LO WITH HI ENTRY
XC 0(L'RENTRY,6),0(7) REPLACE HI WITH LO ENTRY
B RFWD REPEAT FWD PROCEDURE
RDONE EQU *
CLC RKEY,0(7) KEY > BWD TRAVERSAL?
BNH *+22 NO - BYPASS FINAL SWAP
XC 0(L'RENTRY,4),0(7) ISOLATE UNIQUE BITS
XC 0(L'RENTRY,7),0(4) REPLACE LO WITH HI ENTRY
XC 0(L'RENTRY,4),0(7) REPLACE HI WITH LO ENTRY
*
ST 5,8(3) STORE NXT HI IN STACK
LR 5,7 LOAD BWD POINTER ADDRESS
SH 5,=Y(L'RENTRY) DECREMENT BWD (NEW HI)
LA 7,L'RENTRY(,7) INCREMENT BWD (NXT LO)
ST 7,4(3) STORE NXT LO IN STACK
BAL 6,RSORT EXECUTE RECURSIVE SORT
L 4,4(3) LOAD NXT LO ADDRESS
L 5,8(3) LOAD NXT HI ADDRESS
BAL 6,RSORT EXECUTE RECURSIVE SORT
RSORTX EQU *
L 6,0(3) RESTORE LINK REGISTER
SH 3,=H'12' DECREMENT STACK POINTER
BR 6 BRANCH ON LINK REGISTER
***********************************************************************
EJECT
***********************************************************************
DC F'0' RETURN ADDRESS SAVE AREA
TRACE EQU *
ST 6,*-4 SAVE RETURN ADDRESS
*
XFILO STDWKO OPEN OUTPUT FILE
*
LA 6,RTAB LOAD TABLE ADDRESS
RESULTS EQU *
C 6,=A(RTABX) END OF TABLE?
BNL RESULTX YES - EXIT LOOP PLEASE
MVC OPRT(L'RENTRY),0(6) MOVE SORTED ENTRY
XPRNT OREC,81 WRITE OUTPUT RECORD
LA 6,L'RENTRY(,6) BUMP TABLE POINTER
B RESULTS TEST NEXT TABLE ENTRY
RESULTX EQU *
L 6,TRACE-4 RESTORE LINK REGISTER
BR 6 BRANCH ON LINK REGISTER
***********************************************************************
EJECT
***********************************************************************
* WORKING STORAGE *
***********************************************************************
KEY DC CL1' ' KEY STROKE (@RDKEY)
STDWKO DC CL64'C:\TEMP\TDSORTR.OUT' OUTPUT FILE (RESULTS)
OREC DS 0CL133 OUTPUT RECORD
OCC DC CL1' ' DUMMY CARRIAGE CONTROL
OPRT DC CL132' ' PRINT LINE AREA
***********************************************************************
LTORG LITERAL POOL
***********************************************************************
* SUPERVISOR CALLS *
***********************************************************************
@OPEN EQU 1 SUPERVISOR CALL ROUTINE
@CLOSE EQU 2 SUPERVISOR CALL ROUTINE
@GET EQU 5 SUPERVISOR CALL ROUTINE
@PUT EQU 6 SUPERVISOR CALL ROUTINE
@ASCEBC EQU 12 SUPERVISOR CALL ROUTINE
@EBCASC EQU 13 SUPERVISOR CALL ROUTINE
@RDKEY EQU 201 SUPERVISOR CALL ROUTINE
@WTO EQU 209 SUPERVISOR CALL ROUTINE
***********************************************************************
* SAMPLE TABLE - STATE/AREACODE/DESCRIPTION *
***********************************************************************
CNOP 0,4 FULLWORD ALIGNMENT
RTAB EQU *
DC CL25'MD301MARYLAND'
DC CL25'NJ201NEW JERSEY'
DC CL25'DE302DELAWARE'
DC CL25'GA404GEORGIA'
DC CL25'GA706GEORGIA'
DC CL25'WA206WASHINGTON'
DC CL25'AK907ALASKA'
DC CL25'NY607NEW YORK'
DC CL25'NJ908NEW JERSEY'
DC CL25'NJ609NEW JERSEY'
DC CL25'WA509WASHINGTON'
DC CL25'MD410MARYLAND'
DC CL25'PA610PENNSYLVANIA'
DC CL25'GA912GEORGIA'
DC CL25'NY212NEW YORK'
DC CL25'PA412PENNSYLVANIA'
DC CL25'NY914NEW YORK'
DC CL25'PA814PENNSYLVANIA'
DC CL25'NY315NEW YORK'
DC CL25'PA215PENNSYLVANIA'
DC CL25'NY516NEW YORK'
DC CL25'NY716NEW YORK'
DC CL25'NY917NEW YORK'
DC CL25'NY917MANHATTEN'
DC CL25'PA717PENNSYLVANIA'
DC CL25'NY518NEW YORK'
DC CL25'NY718NEW YORK'
DC CL25'PA724PENNSYLVANIA'
DC CL25'NJ732NEW JERSEY'
DC CL25'MD240MARYLAND'
DC CL25'MD443MARYLAND'
DC CL25'WA360WASHINGTON'
DC CL25'GA770GEORGIA'
DC CL25'NJ973NEW JERSEY'
DC CL25'GA678GEORGIA'
RTABX DC C'$'
RKEY DC CL5' ' SORT OBJECT KEY
***********************************************************************
* RECURSION STACK - UP TO 1000 RECURSIVE CALLS SUPPORTED *
***********************************************************************
CNOP 0,4 FULLWORD ALIGNMENT
RSTACK EQU *
DS 1000XL12 RECURSION STACK AREA
***********************************************************************
RDSECT DSECT RTAB DSECT
RENTRY DS 0CL25 TABLE ENTRY
RSTATE DS CL2 STATE
RAREA DS CL3 AREA CODE
RDESC DS CL20 DESCRIPTION
***********************************************************************
END TDSORTR
|