5.29 · exercise

bubble up the order

Six values sit in a tangle in .data. Bubble sort them in place, smallest first; the print loop at the bottom will show whatever order the memory ends up in.

Bubble sort is two nested loops: the outer one counts passes, the inner one walks adjacent pairs, swapping any pair that is out of order. Both elements of a pair load with the scaled-index form, and a swap is simply storing them back in each other's slots. After each pass the largest remaining value has bubbled to the end, so the inner walk can shrink as the passes go by.

what is checked

  • six lines, the values in ascending order
  • the program exits cleanly
  • the sort rearranges memory (str present, comparisons present)

Specification

args
stdoutprints the expected output
exitexits with the expected code
sourceuses str
sourceuses cmp

Checked by running your program against expected behavior, never by matching a stored solution.

loading editor...
Open in playground