title: ARM - Infinite Loop While Searching String
body: <p>Can anybody point out why? I can't see the problem.</p>
  
  <p>String to search: "aassaas"</p>
  
  <p>String to search with: "as"  </p>
  
  <pre><code>SEARCHSTRING:
    STMFD SP!, {R4-R7, LR} 
  
    MOV R6, #0               @Matches found
    MOV R3, #0               @Placeholder     
  
  LOOP: LDRB R4, [R0]        @R4 = String to search
    LDRB R5, [R1]            @R5 = String to search with
  
    CMP R4, R5               @Do they match?
    ADDEQ R3, R3, #1         @If yes, increase placeholder
    LDREQB R4, [R0, #1]!     @Get next char
    LDREQB R5, [R1, #1]!     @Get next char
    BLNE RESET               @If not, reset placeholder and strings.
                             @R0 is nevertheless initial pos+1
    CMP R5, #0               @Is string to search with at the end?
    ADDEQ R6, R6, #1         @If so, add +1 to matches
    BLEQ RESET               @Reset placeholder and strings.
  
    CMP R4, #0               @Is the string to search finished?
    BNE LOOP                 @If not, start over.
  
    MOV R0, R6               @If so, move answer into R0.
    LDMFD SP!, {R4-R7, PC}   @Jump back.
  
  RESET:
    STMFD SP!, {LR}
  
    CMP R3, #0               @Is the placeholder at 0? (initial position)
    SUBNE R0, R0, R3         @If not, subtract from String to search pos
    SUBNE R1, R1, R3         @And string to be searched pos
    ADDNE R0, R0, #1         @Increment string to search+1 so we don't start at the same spot
    MOVNE R3, #0             @Empty the placeholder
  
    LDMFD SP!, {PC}          @Jump back
  </code></pre>