SHARE
TWEET

Untitled

a guest Oct 20th, 2019 232 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     .text
  2.     .global sort_by_age
  3.  
  4. sort_by_age:
  5.     push {r4, r5, r6, r7, r8, r9, lr}
  6.  
  7.     mov r4, r0 // N
  8.     mov r5, r1 // *persons
  9.  
  10.     mov r6, #0 // i
  11.     mov r7, #1 // j
  12.    
  13.     b loop
  14.  
  15. loop:
  16.     cmp r6, r4
  17.     beq finish
  18.  
  19.     add r7, r6, #1 // j = i + 1
  20.     mov r8, r6 // index_min = i
  21.     b sorting
  22.  
  23. finish:
  24.     pop {r4, r5, r6, r7, r8, r9, lr}
  25.     bx lr
  26.  
  27. sorting:
  28.     cmp r7, r4
  29.     beq swap
  30.  
  31.     mov r0, #48
  32.     mul r0, r0, r7
  33.     add r0, #4
  34.     ldrb r2, [r5, r0] // persons[j].age
  35.  
  36.     mov r1, #48
  37.     mul r1, r1, r8
  38.     add r1, #4 
  39.     ldrb r3, [r5, r1] // persons[index_min].age
  40.  
  41.     cmp r2, r3
  42.     movlt r8, r7
  43.  
  44.     add r7, #1
  45.  
  46.     b sorting
  47.  
  48. loop_end:
  49.     add r6, #1
  50.  
  51.     b loop
  52.  
  53. swap:
  54.     cmp r8, r6
  55.     beq loop_end
  56.  
  57.     mov r9, #0 //helper
  58.     b loop_swap
  59.  
  60. loop_swap:
  61.     cmp r9, #48
  62.     beq loop_end
  63.  
  64.     mov r0, #48
  65.     mul r0, r0, r6
  66.     add r0, r9
  67.  
  68.     mov r1, #48
  69.     mul r1, r1, r8
  70.     add r1, r9
  71.  
  72.     ldrb r2, [r5, r0]
  73.     ldrb r3, [r5, r1]
  74.     strb r2, [r5, r1]
  75.     strb r3, [r5, r0]
  76.  
  77.     add r9, #4
  78.     b loop_swap
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top