Advertisement
aaaaaa123456789

Attempt at string functions

Jul 30th, 2015
309
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // r0 = destination, r1 = source, r2 = length, r3 = op (b2: str2 is 16-bit, b1: str1 is 16-bit, b0: 0 = compare, 1 = copy)
  2. // reads use r4 and return in r5, writes use r0 and r5
  3.  
  4. push {r4-r9, lr}
  5. and r7, r3, #4
  6. and r6, r3, #2
  7. mov r6, r6 lsl #1
  8. mov r3, r3, lsl #2
  9. and r3, r3, #4
  10. add r7, r7, r3 lsl #1
  11. add r4, pc, #0xC
  12. add r5, r4, #0x10
  13. ldr r6, [r4, r6]
  14. ldr r7, [r4, r7]
  15. ldr r3, [r5, r3]
  16. bx r3
  17. .word read_char8
  18. .word read_char16
  19. .word write_char8
  20. .word write_char16
  21. .word str_compare
  22. .word str_copy
  23.  
  24. str_copy:
  25. push {r0}
  26. mov r4, r1
  27. loop_copy:
  28. bl character_op_2
  29. cmp r5, #0
  30. moveq r2, #1
  31. bl character_op_1
  32. subs r2, r2, #1
  33. bne loop_copy
  34. pop {r0, r4-r9, pc}
  35.  
  36. str_compare:
  37. mov r4, r0
  38. bl character_op_1
  39. push {r5}
  40. mov r0, r4
  41. mov r4, r1
  42. bl character_op_2
  43. mov r1, r4
  44. pop {r3}
  45. subs r3, r3, r5
  46. bne done_compare
  47. subs r2, r2, #1
  48. beq done_compare
  49. cmp r5, #0
  50. bne str_compare
  51. done_compare:
  52. mov r0, r3
  53. pop {r4-r9, pc}
  54.  
  55. character_op_1:
  56. bx r6
  57.  
  58. character_op_2:
  59. bx r7
  60.  
  61. read_char8:
  62. ldrb r5, [r4], #1
  63. eor r3, r5, #0xFF
  64. clz r8, r3
  65. subs r8, #25
  66. bxle lr
  67. rsb r8, r8, #6
  68. mov r3, #1
  69. rsb r3, r3, r3 lsl r8
  70. and r5, r5, r3
  71. mov r3, r8 lsl #1
  72. add r3, r3, r8 lsl #2
  73. mov r5, r5 lsl r3
  74. loop_read8:
  75. ldrb r8, [r4], #1
  76. subs r3, r3, #6
  77. and r8, r8, #0x3F
  78. orr r5, r5, r8 lsl r3
  79. bne loop_read8
  80. bx lr
  81.  
  82. read_char16:
  83. ldrh r5, [r4], #2
  84. and r3, r5, #0xFC00
  85. cmp r3, #0xD800
  86. bxne lr
  87. bic r5, r5, #0xFC00
  88. mov r5, r5 lsl #10
  89. add r5, r5, #0x10000
  90. ldrh r3, [r4], #2
  91. bic r3, r3, #0xFC00
  92. add r5, r5, r3
  93. bx lr
  94.  
  95. write_char8:
  96. bics r3, r5, #0x7F
  97. streqb r5, [r0], #1
  98. bxeq lr
  99. mov r8, #0
  100. sub r3, r8, #0x200000
  101. bic r5, r5, r3
  102. mov r3, #26
  103. loop_write8:
  104. and r9, r5, #0x3F
  105. orr r9, r9, #0x80
  106. orr r8, r9, r8 lsl #8
  107. mov r5, r5 lsr #6
  108. clz r9, r5
  109. add r3, r3, #1
  110. cmp r9, r3
  111. blt loop_write8
  112. sub r3, r3, #2
  113. mov r9, #0x80000000
  114. orr r9, r5, r9 asr r3
  115. strb r9, [r0], #1
  116. loop_shiftout:
  117. strb r8, [r0], #1
  118. movs r8, r8 lsr #8
  119. bne loop_shiftout
  120. bx lr
  121.  
  122. write_char16:
  123. tst r5, #0x1F0000
  124. streqh r5, [r0], #2
  125. bxeq lr
  126. mov r3, r5 lsr #10
  127. eor r5, r5, r3 lsl #10
  128. orr r5, r5, #0xDC00
  129. sub r3, r3, #0x40
  130. orr r5, r5, #0xD800
  131. strh r3, [r0], #2
  132. strh r5. [r0], #2
  133. bx lr
Advertisement
RAW Paste Data Copied
Advertisement