Program to arrange a series of 32 bit numbers in ascending/descending order

Write a program to arrange a series of 32 bit numbers in ascending/descending order

Program:-

Ascending:-

    AREA SORT,CODE,READONLY
    ENTRY
    MOV R5,#3
NXTPASS LDR R0,VALUE
    MOV R4,R5
NXTCOMP LDR R1,[R0],#4
    LDR R2,[R0]
    CMP R1,R2
    BLS NOEXG
    STR R1,[R0],#-4
    STR R2,[R0],#4
NOEXG SUBS R4,#1
    BNE NXTCOMP
    SUBS R5,#1
    BNE NXTPASS
STOP B STOP
VALUE DCD 0x40000000
    END

Descending:-

    AREA SORT,CODE,READONLY
    ENTRY
    MOV R5,#3
NXTPASS LDR R0,VALUE
    MOV R4,R5
NXTCOMP LDR R1,[R0],#4
    LDR R2,[R0]
    CMP R1,R2
    BHS NOEXG
    STR R1,[R0],#-4
    STR R2,[R0],#4
NOEXG SUBS R4,#1
    BNE NXTPASS
STOP B STOP
VALUE DCD 0x40000000
    END

Leave a Reply

Your email address will not be published. Required fields are marked *