I'm using ubuntu 32 bits to code in assembly. And I'm trying to do a program to order a string in alphabetical order, but it's not working correctly.
I declared the string. I used lea to place the string in the eax register. Then used movl(%eax), %ebx
, to copy the first memory cell (0) of the string that would be the "l", to then compare it with the second memory cell (1) that would be the"h".
In the next cycle, to compare the second memory cell with the third memory cell I did inc %eax
so that it would do movl 1(%eax), %ebx
instead movl (%eax), %ebx
. This is my code:
.data
str: .string "lhtgbvfmjnbcdsaawcfr"
.text
.globl main
main:
movl $19, %ecx
inicio:
leal variavel, %eax
movl (%eax), %ebx
cmpl %ebx, 1(%eax)
JA maior
JB menor
maior:
xchg %ebx, 1(%eax)
xchg (%eax), %ebx
menor:
inc %eax
decl %ecx
cmpl $0, %ecx
JA inicio
JE main
What i did didn't work, so clearly there is something wrong, I've searched about assembly but I haven't found many things. Is there anyone that can help me?