Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   Bubble sort getting max number (http://www.go4expert.com/forums/bubble-sort-getting-max-t10517/)

Black Baron 10May2008 13:05

Bubble sort getting max number
 
Hey there ..
I did a bubble sort alp to sort a byte list in descending order .. the idea of the bubble sort is to compare between the first two elements then if one is bigger it goes to the beginning of the list ..
The list is for example: 2,4,1,3,7,9,11 .. NUMBER DB 2,4,1,3,7,9,11

That's the code :
Code:

        MOV SI,O ; SI is the first number in the list
        MOV DI,0 ; DI is the number compared with SI
        MOV AL,NUMBER[SI]
        MOV DI,SI
        INC DI

INNER:
        CMP AL,NUMBER[DI]
        JLE SWAP

CONITNUE:
        INC DI
        CMP DI,7
        JNE INNER
        INC SI
        CMP SI,6
        JNE OUTER
        JMP FINISH

SWAP:
        MOV DL,NUMBER[DI]
        XCHG NUMBER[SI],DL
        MOV NUMBER[DI],DL
        MOV AL,NUMBER[SI]
        JMP CONTINUE
FINISH:
        MOV AX,4C00H
        INT 21

Now, I want to get the maximum number .. what do you think if I take the value of SI at the end because it will be the maximum .. how can I do that in this code ?

Thanks guys .


All times are GMT +5.5. The time now is 15:29.