Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text
- .align 2
- .global replace
- .type replace, %function
- @ r0 first word
- @ r1 second word
- @ r2 third word
- @ r3 first word letter
- @ r4 second word letter
- @ r5 third word letter
- @ r6 i iterator
- @ r7 j iterator
- replace:
- MOV r6, #0 @ i = 0
- first_iteration:
- MOV r7, #0 @ j = 0
- @ get the letter from first word
- LDRB r3, [r0, r6]
- CMP r3, #0 @ Last letter \0
- BEQ exit @ the the word was fully processed
- second_iteration:
- @ get the letter from second word
- LDRB r4, [r1, r7]
- @ If second word ended exit second iteration
- CMP r4, #0
- BEQ first_iteration_increase
- @ If letters from both words are equal
- @ Grab and replace in first word
- CMP r3, r4
- BEQ swap_letters
- second_iteration_increase:
- ADD r7, r7, #1 @move by byte
- B second_iteration
- first_iteration_increase:
- ADD r6, r6, #1 @move by byte
- B first_iteration
- swap_letters:
- LDRB r5, [r2, r7] @takes the letter to replace
- STRB r5, [r0, r6] @ replaces letter in w1
- B first_iteration_increase
- exit:
- BX lr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement