-
Notifications
You must be signed in to change notification settings - Fork 1
/
bubble_sort.s
50 lines (43 loc) · 882 Bytes
/
bubble_sort.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
ldr r0,=aa @address of first element of array
ldr r1,=N @address of size of array
ldr r7,[r1] @ size of array
mov r8,#4
sub r9,r7,#1
mov r2,#0 @i=0 for outer loop
outerloop:
mov r3,#0 @j=0 for innner loop
add r2,r2,#1
cmp r2,r7
beq exit
innerloop:
mul r4,r3,r8
ldr r5,[r0,r4]
add r4,r4,#4
ldr r6,[r0,r4]
cmp r5,r6
ble comp
@for swap
str r5,[r0,r4]
sub r4,r4,#4
str r6,[r0,r4]
comp:
add r3,r3,#1 @update j=j+1
cmp r3,r9
bne innerloop
beq outerloop
exit:
ldr r2,[r0]
ldr r3,[r0,#4]
ldr r4,[r0,#8]
ldr r5,[r0,#12]
ldr r6,[r0,#16]
ldr r7,[r0,#20]
ldr r8,[r0,#24]
ldr r9,[r0,#28]
ldr r10,[r0,#32]
ldr r11,[r0,#36]
ldr r12,[r0,#40]
.data
N: .word 11
aa: .word 2,45,12,54,8,2,1,4,19,25,0
.end