I'm trying to figure out sorting an array of strings using assembly. I compare the first and the second alphabets and then rearrange them in alphabethic order. I have it almost figured out but my output is rearranging some character incorrectly. For example, when printing 'eight', it'll just print 'eigh'.
.386
public _Sort
.model flat
.code
_Sort proc
push ebp
mov ebp, esp
push esi
push edi
mov ecx, 10
mov eax, 1
dec ecx
L1:
push ecx
mov esi, [ebp+8]
L2:
mov al, [esi]
cmp [esi + 20], al
jg L3
mov eax, [esi]
xchg eax, [esi + 20]
mov [esi], eax
L3:
add esi, 20
loop L2
pop ecx
loop L1
L4:
pop edi
pop esi
pop ebp
ret
_Sort endp
end
#include <iostream>
using namespace std;
extern "C" int Sort (char [] [20], int, int);
void main ()
{
char Strings [10] [20] = { "One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten" };
int i;
cout << "Unsorted Strings are" << endl;
for (i = 0; i < 10; i++)
cout << '\t' << Strings [i] << endl;
Sort (Strings, 10, 20);
cout << "Sorted Strings are" << endl;
for (i = 0; i < 10; i++)
cout << '\t' << Strings [i] << endl;
}