• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

68k selection sort help

Status
Not open for further replies.

kt1991

Junior Member
I am using easy68k to write a selection sort program, my main issue currently is I do not know how to select the largest value move it to the new memory location and then block off that highest value (i.e my highest value is 30 I need to remove it from the memory otherwise I would keep selecting 30 as the largest number)

Code:
ORG    $400
START:    
    LEA    Name,A1    Points to name
    MOVE.W    #11,D1    11 characters that need to be printed
    MOVE.B    #0,D0
    Trap    #15
    LEA    Class,A1 Points to Info
    MOVE.W    #7,D1    7 characters to be printed
    MOVE.B    #0,D0
    Trap    #15
    LEA    Info,A1    Points to Info
    MOVE.W    #9,D1    9 characters to be printed
    MOVE.B    #0,D0
    Trap    #15
    BSR    PRINT    
    MOVEA.L #Data, A0
    MOVEA.L    #Sorted, A3        
    CLR.B     D0
    CLR.B    D4
        
Next    MOVE.B    (A0),D1    This portion selects the largest number
    BEQ    Exit
    CMP.B    D0,D1
    BLS    EndTest
    MOVE.B    D1, D0    
    MOVE.B    D0, (A3)    Should point to the new array and store a value
                
EndTest    MOVE.B    #-1,(A0)    replaces the original value with negative one because the program ends when the pointer reaches 0 in the data and -1 < 0
    ADDA.L    #1,A0    
    MOVE.L    D0,(A3,D4)    Point to sorted array and D4 will increment it by 1 allowing for the new highest value to be stored in the next memory block
    BEQ    Exit
    BRA    Next
    MOVEA.L    #1,A1    
Exit    BSR    PS
    
    STOP    #$2700
PRINT    LEA    Data,A1 Points to Info    
L1    MOVE.B    (A1)+,D6
    MOVE.W    D6,D1    41 characters to be printed
    MOVE.B    #3,D0
    Trap    #15
    CMP.B    #35,(A1)
    BLE    L1
    RTS



PS    LEA    Sorted, A3
L2    
    MOVE.B    (A3)+,D6
    MOVE.W    D6,D1    41 chracters to be printed
    MOVE.B    #3,D0
    Trap    #15
    CMP.B    #100,(A1)
    BLE    L2
    RTS

*
    ORG $1000
Data    DC.B    10,12,8,17,9,22,18,11,23,7,30,22,19,6,7,0
Name    DC.B    'XXXXX'
Class    DC.B    'CIS 310'
Info    DC.B    'Fall 2011'
Sorted    DS.B    15
    END $400

In the future be forthright about the fact that you are working on a homework or lab problem, and post specific questions rather than a broad "How do I do everything I need to do for this exercise?" type of inquiry.

Markbnj
Programming moderator
 
Last edited by a moderator:
OK, first question: Why on earth would you write a selection sort in assembly? (Unless it's homework, which you should disclose if it is.)

Second, Selection sort is most easily performed in the array you're sorting. (No extra array, so if you need it sorted in a new array copy everything there first.) When you find the biggest number, excluding the end you've already sorted, swap that number with the next number at the end you've already sorted. Does that make sense?
 
A quick google search shows this is a homework problem (well, a lab exercise from Chico State actually). You should ask your professor or TA.
 
Status
Not open for further replies.
Back
Top