bubble sort

Now i should write a bubble sort algorithm
but i should not use stack segment.
DL : number of element
BX : flag register
And here is my bubble sort it is not working but i haven't find the mistake.

SORT_DATA :
XOR DH,DH ;mov registers zero
XOR BX,BX
XOR AX,AX
MOV CX,DX ;couter register has now element size
;of data
DEC CX ;n-1 iteration
MOV SAVE_COUNT,CX ;store cx
INIT :
MOV BX,1 ;flag = false
MOV CX,SAVE_COUNT
MOV DI,0
NEXT :
MOV AL,DATA[DI] ;al has now DI .th element of data
CMP DATA[DI+1],AL ;check which is greater than other
JAE CONT
XCHG DATA[DI+1],AL ;we perform here swap
MOV DATA[DI],AL ;it is necessary because we changed
;the values of AL and DATA[DI]
XOR BX,BX ;flag = true
CONT :
INC DI ;to reach next element of data
LOOP NEXT
CMP BX,0
JE INIT
SORTED :
RET
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories