You are on page 1of 32

Sort the list of 32-bit numbers

6) Write a program to sort given array In ascending descending order


AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033,0x0044,0x0055,0x0066,0x0077,0x0088,0x0099 ,0x00AA
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0]
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descening
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
• Create new file sort.s
• Make sure that Startup.s is removed from project
• Rebuild

• Debug

• Use this option add any memory bank


• Use F10 for step by step execution
AREA Data1, READONLY

N DCD 03 ; total numbers to be sorted (here for descending order)

ALIGN
AREA Data2, DATA,READWRITE

List DCD 0x0011,0x0022,0x0033


AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0]
Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
Use memory bank to edit the values
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
Three values 11,22,23 are edited..
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
Use memory bank to see the values
LDR R0,=N ; setup the counter Use memory bank to edit the values
LDR R1,[R0] Three values 11,22,23 are edited..
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
Use memory bank to see the values
LDR R0,=N ; setup the counter
Use memory bank to edit the values
LDR R1,[R0] Three values 11,22,23 are edited..
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
Use memory bank to see the values
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to edit the values
Three values 11,22,23 are edited..
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)

Outer LDR R5,=List ; point to the array


MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE

List DCD 0x0011,0x0022,0x0033


AREA SORT, CODE, READONLY
ENTRY Use memory bank to see the values
LDR R0,=N ; setup the counter
LDR R1,[R0]
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration) Use memory bank to edit the values
Three values 11,22,23 are edited..
Outer LDR R5,=List ; point to the array

MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)


inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
Three values 11,22,23 are edited..
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)

inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..

inner LDR r6, [r5], #4 ; load two consecutive data from memory

LDR r7, [r5]


CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..
inner LDR r6, [r5], #4 ; load two consecutive data from memory

LDR r7, [r5]


CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]

CMP r6, r7 ; compare them

BGE Skip ; If first number is lesser than second then swap (BLE for ascending )

STR R6, [R5] ; swap by loading Smaller data ( R6 ) current


STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )

STR R6, [R5] ; swap by loading Smaller data ( R6 ) current

STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current

STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending

Skip SUBS r2, r2, #1 ; decrement number comparison remaining


BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending

Skip SUBS r2, r2, #1 ; decrement number comparison remaining

BNE inner ; repeat if not 0

SUBS r1, r1, #1 ; update number of iteration remaining


BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..

inner LDR r6, [r5], #4 ; load two consecutive data from memory

LDR r7, [r5]


CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..
inner LDR r6, [r5], #4 ; load two consecutive data from memory

LDR r7, [r5]


CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]

CMP r6, r7 ; compare them

BGE Skip ; If first number is lesser than second then swap (BLE for ascending )

STR R6, [R5] ; swap by loading Smaller data ( R6 ) current


STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )

STR R6, [R5] ; swap by loading Smaller data ( R6 ) current

STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to edit the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration) Three values 11,22,23 are edited..
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current

STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending

Skip SUBS r2, r2, #1 ; decrement number comparison remaining


BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0]
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to see the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5] Use memory bank to edit the values
CMP r6, r7 ; compare them Three values 11,22,23 are edited..
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending

Skip SUBS r2, r2, #1 ; decrement number comparison remaining

BNE inner ; repeat if not 0

SUBS r1, r1, #1 ; update number of iteration remaining


BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0]
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Outer LDR R5,=List ; point to the array Use memory bank to see the values
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5] Use memory bank to edit the values
CMP r6, r7 ; compare them Three values 11,22,23 are edited..
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0

SUBS r1, r1, #1 ; update number of iteration remaining

BNE outer ; repeat again if not over

STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Use memory bank to edit the values
Outer LDR R5,=List ; point to the array Three values 11,22,23 are edited..
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Use memory bank to edit the values
Outer LDR R5,=List ; point to the array Three values 11,22,23 are edited..
MOV r2, r1; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Use memory bank to edit the values
Outer LDR R5,=List ; point to the array Three values 11,22,23 are edited..
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)

inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Use memory bank to edit the values
Outer LDR R5,=List ; point to the array Three values 11,22,23 are edited..
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory

LDR r7, [r5]


CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Use memory bank to edit the values
Outer LDR R5,=List ; point to the array Three values 11,22,23 are edited..
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]

CMP r6, r7 ; compare them


BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Use memory bank to edit the values
Outer LDR R5,=List ; point to the array Three values 11,22,23 are edited..
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )

STR R6, [R5] ; swap by loading Smaller data ( R6 ) current


STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Use memory bank to edit the values
Outer LDR R5,=List ; point to the array Three values 11,22,23 are edited..
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current

STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Use memory bank to edit the values
Outer LDR R5,=List ; point to the array Three values 11,22,23 are edited..
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending

Skip SUBS r2, r2, #1 ; decrement number comparison remaining


BNE inner ; repeat if not 0
SUBS r1, r1, #1 ; update number of iteration remaining
BNE outer ; repeat again if not over
STOP B STOP
END
AREA Data1, READONLY
N DCD 03 ; total numbers to be sorted (here for descending order)
ALIGN
AREA Data2, DATA,READWRITE
List DCD 0x0011,0x0022,0x0033
AREA SORT, CODE, READONLY
ENTRY
LDR R0,=N ; setup the counter
LDR R1,[R0] Use memory bank to see the values
SUB r1, r1, #1 ; Outer loop counter ( n-1 iteration)
Use memory bank to edit the values
Outer LDR R5,=List ; point to the array Three values 11,22,23 are edited..
MOV r2, r1 ; setup inner loop ( number of comparisons in each iteration)
inner LDR r6, [r5], #4 ; load two consecutive data from memory
LDR r7, [r5]
CMP r6, r7 ; compare them
BGE Skip ; If first number is lesser than second then swap (BLE for ascending )
STR R6, [R5] ; swap by loading Smaller data ( R6 ) current
STR R7, [R5, #-4] ; and Bigger to previous location- to get in descending
Skip SUBS r2, r2, #1 ; decrement number comparison remaining
BNE inner ; repeat if not 0

SUBS r1, r1, #1 ; update number of iteration remaining


BNE outer ; repeat again if not over
STOP B STOP
END
For descending order BGE by BLE
•‘
•‘
•‘
CMP r6, r7 ; compare them
BLE Skip

You might also like