1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Bubble sort getting max number

Discussion in 'Assembly Language Programming (ALP) Forum' started by Black Baron, May 10, 2008.

  1. Black Baron

    Black Baron New Member

    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 .
     

Share This Page