-1

I am trying to make a program that accepts user input and sorts the characters of a string input in ascending order.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
How
  • 1
  • 4

1 Answers1

-1

The sorting algorithm used can vary, but a common approach is to use a bubble sort algorithm.

.data
string db 'sortstring',0
sorted db 20 dup(0)

.code
main proc
    mov edx, offset string
    mov ecx, lengthof string
    call sort_string
    ; ...
    ; Output sorted string here
    ; ...
    ret
main endp

sort_string proc
    push ebp
    mov ebp, esp
    ; ...
    ; Sort the characters of the string here
    ; ...
    pop ebp
    ret
sort_string endp
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Dima C
  • 39
  • 9
  • 1
    Bubble Sort is an in-place sorting algorithm. If you want to copy-and-sort into a separate `sorted db 20 dup(?)` buffer, you'd have to use a better algorithm like Insertion Sort. You're not showing an implementation of a sort (there are many duplicates for that), or for reading user input (again many duplicates), just a skeleton of a different problem, copy-and-sort of a hard-coded string. – Peter Cordes Jan 30 '23 at 18:11