Advertisement
Guest User

Bubble Sort

a guest
Jan 23rd, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.15 KB | None | 0 0
  1.         B main
  2.  
  3. array   DEFW    25,10,13,9,44,15,6,2,36,42
  4.  
  5.         ALIGN
  6. main
  7.         MOV R0,#0       ; array[R2]
  8.         MOV R1,#0       ; array[R3]
  9.         MOV R2,#0       ; current_index*4
  10.         MOV R3,#0       ; (current_index+1)*4
  11.  
  12.         MOV R4,#9       ; array length-1
  13.         MOV R5,#0       ; counter
  14.         ; R6 could be used as a "sorted?" check but not required
  15.         ADRL R7,array   ; array address
  16.  
  17. iloop   CMP R4,#1
  18.         BEQ iend
  19.        
  20.         MOV R2,#0
  21.         MOV R3,#4
  22.  
  23. jloop   CMP R5,R4
  24.         BEQ jend
  25.  
  26.         LDR R0,[R7,R2]
  27.         LDR R1,[R7,R3]
  28.  
  29.         CMP R0,R1
  30.         BGT no_swap
  31.  
  32.         STR R0,[R7,R3]
  33.         STR R1,[R7,R2]
  34.  
  35. no_swap ADD R2,R2,#4
  36.         ADD R3,R3,#4
  37.         ADD R5,R5,#1
  38.         B jloop
  39.  
  40. jend    BL print
  41.         SUB R4,R4,#1
  42.         MOV R5,#0
  43.         B iloop
  44.  
  45. iend    SWI 2
  46.  
  47. print   STMFD R13!, {R0-R7, R14}
  48.  
  49.         MOV R0,#0
  50.         MOV R1,#0
  51.         ADR R2,array
  52.  
  53. ploop   CMP R1,#40
  54.         BEQ pend
  55.         LDR R0,[R2,R1]
  56.         SWI 4
  57.         MOV R0,#44
  58.         SWI 0
  59.         ADD R1,R1,#4
  60.         B ploop
  61.  
  62. pend    MOV R0,#13
  63.         SWI 0
  64.         LDMFD R13!, {R0-R7, PC}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement