I have been working on converting a selection sort pseudocode to assembler 370 code. The pseudocode is as follows:

BEGIN initially is a pointer to the first entry
END is a pointer to the last entry
I and LOW are also pointers
1 is the length of one entry

Do While (BEGIN < END)
  LOW <- BEGIN
  I <- BEGIN + 1
  Do While (I not > END)
    If Key (LOW) > Key (I)
      LOW <- I
    Endif
    I <- I + 1
  Enddo
  Swap ENTRY (BEGIN) with ENTRY (LOW) 
  BEGIN = BEGIN + 1
Enddo;

I have the following done but dose not have any effect on the table that is to be sorted.

SORT     DS    0H                            
* STEP<1>                                    
         STM   0,15,SORTSAVE                 
         LM    2,3,0(1)       LOAD PARAMETERS
         L     3,0(3)         LOADING END OF TABLE 
*                            REGISTER THREE IS THE END OF TABLE                
LOOP1    CR    2,3   REGISTER TWO IS THE BEGINNING OF THE TABLE                
         BH    ENDLP1                        

*    storage for number values(LOW and I)
              
         LA    5,0(2)    LOW                 
         LA    6,4(2)    I                   
*                                            
LOOP2    CR    6,3                           
         BH    ENDLP2                        
*                                            
         CR    5,6                           
         BH    SET                           
*                                            
         B     PASS                          
*                                                     
SET      LA    5,0(6)                                 
*                                                     
PASS     DS    0H                                     
         LA    6,4(6)                                 
ENDLP2   DS    0H                                     
*    SWAPING BEGIN WITH LOW                           
         LA    7,0(2)         HOLDING REGISTER TWO CONTENTS     
         LA    2,0(5)         REPLACING BEGIN WITH LOW
         LA    5,0(7)         REPLACING LOW WITH BEGIN
*                                                     
         LA    2,4(2)         MOVING TO NEXT ENTRY    
ENDLP1   DS    0H                                     
*                                                     
         LM    0,15,SORTSAVE                          
*                                                     
         BR    10                                     
         LTORG                                        
*                                                     
SORTSAVE DS    16F            STORAGE FOR REGISTERS
*;

Does anyone have any suggestions ?

Thank You

Do you need a solution?

* BY COMPUTER FREELANCE SRL - ITALY
* Gabriele Cagliani
CFSORT CSECT
SAVE (14,12) SAVE INPUT REGISTERS
LR 12,15 12 = BASE REGISTER
USING CFSORT,12 ASSIGN BASE
ST 13,SAVE+4 SAVE OLD SAVE AREA ADDRESS
LA 11,SAVE POINT TO NEW SAVE AREA
ST 11,8(13) IN OLD SAVE AREA
LR 13,11 MOVE SAVE AREA ADDRESS

LM 2,3,0(1) LOAD PARAMETERS
* THE TABLE IS A SEQUENCE OF KEYS
LA 3,0(3) CLEAR HIGH ORDER BIT
* REGISTER THREE IS THE END OF TABLE (LAST ELEMENT)
LOOP1 CR 2,3 REGISTER TWO IS THE BEGINNING OF THE TABLE
BNL ENDLP1
LA 5,0(2) LOW
LA 6,KEYLEN(2) I
*
LOOP2 CR 6,3 END OF TABLE ?
BH ENDLP2
*
CLC 0(KEYLEN,5),0(6)
BNH PASS
LA 5,0(6)
PASS DS 0H
LA 6,KEYLEN(6)
B LOOP2
ENDLP2 DS 0H
* SWAPING BEGIN WITH LOW
MVC KEYSAVE,0(2) SAVE
MVC 0(KEYLEN,2),0(5) REPLACING BEGIN WITH LOW
MVC 0(KEYLEN,5),KEYSAVE REPLACING LOW WITH BEGIN
*
LA 2,KEYLEN(2) MOVING TO NEXT ENTRY
B LOOP1
ENDLP1 DS 0H
*
L 13,SAVE+4 GET OLD SAVE AREA BACK
RETURN (14,12),RC=0
*
LTORG
*
SAVE DS 18F STORAGE FOR REGISTERS
KEYSAVE DS CL8 KEY
KEYLEN EQU L'KEYSAVE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.