I am trying to make a program that accepts user input and sorts the characters of a string input in ascending order.
1 Answer
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
1 Comment
Peter Cordes
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.