Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Hi everyone, I'm trying to implement a function in x86 assembly that sorts a given array of characters in descending order according to its ASCII code. The inputs are an array of characters and the size of the array.
In my case, the given array contains "cOmPuTeR" so the result should be "umecTRPO"
This is the pseudocode that I'm trying to follow:
/* bubble sort pseudocode
for(i=(arraySize - 1); i>=0; i--)
for(j=1; j<=1; j++)
if(arrayOfLetters[j-1] < arrayOfLetters[j])
temp = arrayOfLetters[j-1]
arrayOfLetters[j-1] = arrayOfLetters[j]
arrayOfLetters[j] = temp
Here is my code, when I try to run it I just get the original array back and the sort is not working at all.
int descending_sort( char arrayOfLetters, int arraySize )
mov ebx, arrayOfLetters //initialize array
mov esi, arraySize //i
dec esi //i-1
mov edi, 1 //j
mov ecx, 0
cmp esi, ecx
cmp edi, esi
mov al, byte ptr[ebx + edi * 1 - 1]
mov dl, byte ptr[ebx + edi * 1]
cmp al, dl
mov temp, al
mov al, dl
mov dl, temp
I appreciate any suggestions, thanks for your time.