chmpgne

ARM bubblesort

Jul 13th, 2012
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. AREA BubbleSort, CODE, READONLY
  2.     ENTRY
  3.    
  4. Start
  5.     MOV r0, #0 ; array index being sorted
  6.     MOV r12, #0; whether there haven't been any swaps
  7.     ADR r1, DataStart ; get data start address
  8.     ADR r2, DataEnd   ; get data end address
  9.     MOV r12, #0
  10.     ADD r5, r0, #4
  11.     MOV r9, r1
  12.     ADD r5, r9, #4
  13. Loop
  14.     LDR r3, [r9]
  15.     LDR r4, [r5]
  16.     CMP r3, r4
  17.     STRGT r3, [r5]
  18.     STRGT r4, [r9]
  19.     MOVGT r12, #1
  20.     ADD r9, r9, #4
  21.     ADD r5, r9, #4
  22.     CMP r2, r5
  23.     BNE Loop
  24.     CMP r12, #1
  25.     BNE EndSort
  26.     B Start
  27. EndSort
  28.     CMP r1, r2
  29.     BEQ Stop
  30.     LDR r0, [r1], #4
  31.     SVC 2
  32.     B EndSort
  33.     ; **** One way to use the SVCs
  34.     ; **** (as sub-routine calls to the SVCs)
  35.    
  36. DumpRegs
  37.     SVC 1 ; debug command to dump all registers
  38.     MOV pc, lr ; return to calling sub-routine
  39.    
  40. PrintR0
  41.     SVC 2 ; debug command to printR0
  42.     MOV pc, lr ; return to calling sub-routine
  43.    
  44. Stop
  45.     BL DumpRegs ; print all the registers
  46.     SVC 0 ; stop the emulator
  47.    
  48.    
  49. ; *** The data values to be sorted
  50. ; *** Multiple DCDs per line support NOT needed
  51. DataStart
  52.     DCD -4
  53.     DCD 2
  54.     DCD 5
  55.     DCD 910
  56.     DCD 10
  57.     DCD -12
  58.     DCD 91
  59.     DCD 11
  60. DataEnd
  61.     END
Advertisement
Add Comment
Please, Sign In to add comment