title: ARM ldrb is setting Wt to -1
body: <p>I made a function in ARM that removes a duplicate character if the same character exists in a previous location. If it finds one, it will remove the duplicate character and shift all values over.</p>
  
  <p>The first argument (r0) is the index of the character to check for duplicates, and the second argument (r1) is the array to look through. For example, if r0 is 3 and r1 points to "hello", it will look at the third element in the string ('l') and after running, the string r1 points to will become "helo" and r0 will return 1, in r0.</p>
  
  <p>The current problem I'm having is that the first <code>ldrb r2, [r1, r0]</code> is setting r2 to -1. I have checked the ARM manual for <code>ldrb</code> returning errors like this, but I haven't been able to find anything like that. I was wondering if anybody knew a solution.</p>
  
  <p>Thanks!</p>
  
  <pre><code>check_if_duplicate:
      push {r4, r5, lr}
      @ Get character at value i in r4
      ldrb r2, [r1, r0]
      mov r3, #0
  duplicate_loop:
      @ Check if the target index is greater than the current index
      cmp r0, r3
      ble duplicate_done
      @ Check if current index is a duplicate
      ldrb r4, [r1, r3]
      cmp r4, r2
      @ Increment iterator and repeat loop if they are not equal
      addne r3, r3, #1
      bne duplicate_loop
      @ If they are equal, then shift all values over
  duplicate_shift_loop:
      @ Find next value
      add r3, r3, #1
      @ Load next value
      ldrb r2, [r1, r3]
      @ Check if new value is the end of the array
      cmp r2, #0
      beq duplicate_shift_done
      @ Use previous index to store value
      sub r5, r3, #1
      @ Store vaue in previous address
      strb r2, [r1, r5]
      @ Do process again
      b duplicate_shift_loop
  duplicate_shift_done:
      @ Store string ending byte
      sub r3, r3, #1
      mov r2, #0
      strb r2, [r1, r3]
      @ Set 1 as the return value
      mov r0, #1
      b d_done
  duplicate_done:
      mov r0, #0
  d_done:
      pop {r4, r5, pc}
  </code></pre>