-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubble_sort.s
65 lines (56 loc) · 999 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
li sp 1000
mv x6 sp # Final array element
#Add values to array
li x10 1
#Push to stack
sw x10 0(sp)
addi sp sp -4
li x10 22
#Push to stack
sw x10 0(sp)
addi sp sp -4
li x10 3
#Push to stack
sw x10 0(sp)
addi sp sp -4
li x10 42
#Push to stack
sw x10 0(sp)
addi sp sp -4
li x10 5
#Push to stack
sw x10 0(sp)
addi sp sp -4
li x10 62
#Push to stack
sw x10 0(sp)
addi sp sp -4
li x7 0 # didntSwap (bool)
li x8 1 # Constant = 1
WhileLoop:
beq x7 x8 End
mv x28 sp # i = sp
addi x28 x28 4 # Primer elemento del array
li x7 1
ForLoop:
bge x28 x6 EndFor
lw x10 0(x28)
addi x28 x28 4
lw x11 0(x28)
addi x28 x28 -4
ble x10 x11 NotSwap
li x7 0
#Swap x10 and x11
mv x12 x10
mv x10 x11
mv x11 x12
sw x10 0(x28)
addi x28 x28 4
sw x11 0(x28)
addi x28 x28 -4
NotSwap:
addi x28 x28 4
beq x0 x0 ForLoop
EndFor:
beq x0 x0 WhileLoop
End: