Selection sort in LC-3 assembly

I'm trying to code selection sort in LC-3 assembly, but after hours of trying, I cannot seem to figure out how to do it. The pseudocode I have written to model my selection sort algorithm is:

for i = 0 to ARRAY.LENGTH - 1 ->   //iterate through every position in array
    min_idx = i                   //find element that will move to position i

    for j = i + 1 to ARRAY.LENGTH ->
        if ARRAY_ADDRESS[j] < ARRAY_ADDRESS[min_idx] ->
            min_idx = j
    swap(ARRRAY_ADDRESS[i], ARRAY_ADDRESS[min_idx])

The array to be sorted is located at ARRAY_ADDRESS somewhere in memory and the the length of the array is stored in the value ARRAY.LENGTH.

Any suggestions or clues where to start? I've written my assembly but it does not seem to work and I have no clue why. Thanks! Here's a link to the text document: https://textuploader.com/dnkrt

1 answer

  • answered 2018-10-09 20:59 GT-OSI

    This is an honor code violation.