Advertisement
Guest User

Untitled

a guest
May 6th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.06 KB | None | 0 0
  1. .text
  2.   .align  2
  3.   .global replace
  4.   .type replace, %function
  5.  
  6. @ r0  first word
  7. @ r1  second word
  8. @ r2  third word
  9.  
  10. @ r3  first word letter
  11. @ r4  second word letter
  12. @ r5  third word letter
  13.  
  14. @ r6  i iterator
  15. @ r7  j iterator
  16.  
  17.  
  18. replace:
  19.   MOV r6, #0 @ i = 0
  20.  
  21.  
  22. first_iteration:
  23.   MOV r7, #0 @ j = 0
  24.  
  25.   @ get the letter from first word
  26.   LDRB r3, [r0, r6]
  27.  
  28.   CMP r3, #0 @ Last letter \0
  29.   BEQ exit @ the the word was fully processed
  30.  
  31.  
  32. second_iteration:
  33.   @ get the letter from second word
  34.   LDRB r4, [r1, r7]
  35.  
  36.   @ If second word ended exit second iteration
  37.   CMP r4, #0
  38.   BEQ first_iteration_increase
  39.  
  40.   @ If letters from both words are equal
  41.   @ Grab and replace in first word
  42.   CMP r3, r4
  43.   BEQ swap_letters
  44.  
  45.  
  46. second_iteration_increase:
  47.   ADD r7, r7, #1 @move by byte
  48.   B second_iteration
  49.  
  50.  
  51. first_iteration_increase:
  52.   ADD r6, r6, #1 @move by byte
  53.   B first_iteration
  54.  
  55.  
  56. swap_letters:
  57.   LDRB r5, [r2, r7] @takes the letter to replace
  58.   STRB r5, [r0, r6] @ replaces letter in w1
  59.  
  60.   B first_iteration_increase
  61.  
  62.  
  63. exit:
  64.   BX lr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement