There is an odd problem with the sorting by major routine (selection sort) which I've noticed happens in both my routine and in the output the professor gave us for our homework. Basically, we have compressed binary data for 18 bytes, then we have an uncompressed major for four bytes, a packed decimal for the GPA, and then 3 bytes of compressed binary data.
When I run the selection sort, it works, after a fashion. But what it does is to have the first 18 bytes correct. Then, it splits up the data and pulls it in from another line in the table.
So, if I have the following data in the original table: Q12345678 password 22112014 CHEM 400 20 04, after sorting, it might change it to Q12345678 password 22112014 SOCI 350 18 03.
Why would it do this?
I keep thinking that the fact that the major is uncompressed data is screwing with the sorting somehow.
Can you take a look at my code and see if there's something more obvious to you than it is to me?
SORTMAJ CSECT
STM 14,12,12(13) SAVE REGISTER CONTENTS
BALR 12,0 ESTABLISH BASE REGISTER
USING BASEPT3,12
BASEPT3 DS 0H
LM 2,3,0(1) LOAD PARAMETERS INTO REGS
*
BEGIN LA 4,0(2) LOADS TABLE PTR INTO R4
LA 5,27(2) LOADS INDEX PTR INTO R5
*
SMLOOP CLC 18(4,4),18(5) COMPARES THE TWO MAJORS
BC B'1100',SKIP1 BRANCHES TO SKIP1 IF NOT HIGHER
C 5,0(3) COMPARES R5 TO END OF TABLE
BC B'1000',SKIP1 BRANCHES TO SKIP1 IF EQUAL
LA 4,0(5) LOADS ADD OF R5 INTO R4
*
SKIP1 LA 5,27(5) LOADS ADD OF NEXT TBL VAL IN R5
C 5,0(3) COMPARES R5 TO END OF TBL (R3)
BC B'0101',SMLOOP BRANCHES TO SMLOOP IF LOWER THAN
CLC 0(27,4),0(2) COMPARES R2 to R4
BC B'1000',SMLOOP IF EQUAL, BRANCHES TO SMLOOP
*
XC 0(27,4),0(2) DOES THE SWAP
XC 0(27,2),0(4)
XC 0(27,4),0(2)
*
LA 2,27(2) MOVES TO NEXT SLOT IN TABLE
C 2,0(3) COMPARES R2 WITH END OF TABLE
BC B'0101',BEGIN IF LOWER THAN, BRANCHES TO BEGIN
*
LM 14,12,12(13) LOADS REGISTERS BACK
BR 14 EXIT TO MAIN ROUTINE
LTORG
STM 14,12,12(13) SAVE REGISTER CONTENTS
BALR 12,0 ESTABLISH BASE REGISTER
USING BASEPT3,12
BASEPT3 DS 0H
LM 2,3,0(1) LOAD PARAMETERS INTO REGS
*
BEGIN LA 4,0(2) LOADS TABLE PTR INTO R4
LA 5,27(2) LOADS INDEX PTR INTO R5
*
SMLOOP CLC 18(4,4),18(5) COMPARES THE TWO MAJORS
BC B'1100',SKIP1 BRANCHES TO SKIP1 IF NOT HIGHER
C 5,0(3) COMPARES R5 TO END OF TABLE
BC B'1000',SKIP1 BRANCHES TO SKIP1 IF EQUAL
LA 4,0(5) LOADS ADD OF R5 INTO R4
*
SKIP1 LA 5,27(5) LOADS ADD OF NEXT TBL VAL IN R5
C 5,0(3) COMPARES R5 TO END OF TBL (R3)
BC B'0101',SMLOOP BRANCHES TO SMLOOP IF LOWER THAN
CLC 0(27,4),0(2) COMPARES R2 to R4
BC B'1000',SMLOOP IF EQUAL, BRANCHES TO SMLOOP
*
XC 0(27,4),0(2) DOES THE SWAP
XC 0(27,2),0(4)
XC 0(27,4),0(2)
*
LA 2,27(2) MOVES TO NEXT SLOT IN TABLE
C 2,0(3) COMPARES R2 WITH END OF TABLE
BC B'0101',BEGIN IF LOWER THAN, BRANCHES TO BEGIN
*
LM 14,12,12(13) LOADS REGISTERS BACK
BR 14 EXIT TO MAIN ROUTINE
LTORG
I'd appreciate the help! Thank you!
Susan