I've been learning the basics of assembly for a couple weeks now and one of the exercises I've found wants me to use a bubblesort to sort an array.

What I have doesn't sort the array though.  Am I doing something wrong here? 



bubbleSort Proc

mov eax, 000000h
mov cx, NUMS_LENGTH-1
xor di, di

l1:
mov ax, NUMS
cmp ax, NUMS
jl l2
xchg NUMS, ax
mov NUMS, ax

l2:
inc di
cmp di, cx
jl l1
dec cx
jnz l1

bubbleSort endp



(Working in v c++)  Any advice or insight would be greatly appreciated.  =)
Posted on 2011-03-06 08:34:59 by Fran71
You simply forgot to get back to the start of the array after each pass.

Put a label L0: before the xor di,di
Then jnz L0 after the dec cx
Posted on 2011-03-06 19:54:44 by Raymond
Are you sorting an array of bytes or words? If it's bytes, you need to switch to an 8-bit register - al, not ax. If it's words, increment di by two between words. Mix-and-match won't work.

Best,
Frank

Posted on 2011-03-09 14:02:41 by fbkotler