title: ARM Assembly function to replace a specific character in a string
body: <p>I'm writing ARM assembly function that replaces a specific character in a string with another and counts the number of times the replacement occurs at the end. So far i have done this:</p>
  
  <pre><code>.global subs    
  subs:   
      stmfd sp!, {v1-v6, lr} //string entry
      mov v1, #0 //set index to 0
      mov v2, #0 // set count to 0       
  loop :
      ldrb v3, [a1], #1
      cmp a2, v3
      strbeq a2, [a1, #-1]
      cmp v3, #0
      bne loop
      mov     a1,v2 //return value    
      ldmfd   sp!, {v1-v6, pc}
  .end
  </code></pre>
  
  <p>Its not giving the right output. Its showing only first character. Equivalent code in C language is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  extern int replace( char * s, char lr, char rp ) ;
  
  int main( int argc, char * argv[] )
  {
  int result ;
  char lr = 'e' ;
  char rp = 'X' ;
  char str[] = "easy to replace" ;
  
  result = replace( str, lr, rp ) ;
  printf( "%d changes, %s\n", result, str ) ;
  
  exit( 0 ) ;
  }
  </code></pre>