title: Convert C-code to ARM Cortex M3 Assembler Code
body: <p>i have got the following c-function</p>
  
  <pre><code>int main_compare (int nbytes, char *pmem1, char *pmem2){
      for(nbytes--; nbytes&gt;=0; nbytes--) {    
          if(*(pmem1+nbytes) - *(pmem2+nbytes) != 0) {
              return 0;
          }
      }
      return 1;
  }
  </code></pre>
  
  <p>and i want to convert it into an ARM - Cortex M3 - assembler code. I'm not really good at this, and i don't have a suitable compiler to test if i do it right. But here comes what i have so far</p>
  
  <pre><code>byte_cmp_loop PROC
  ; assuming: r0 = nbytes, r1=pmem1, r2 = pmem2
  
      SUB R0, R0, #1    ; nBytes - 1 as maximal value for loop counter
  
  _for_loop: 
      ADD R3, R1, R0    ;
      ADD R4, R2, R0    ; calculate pmem + n
      LDRB R3, [R3]     ;
      LDRB R4, [R4]     ; look at this address
  
      CMP R3, R4        ; if cmp = 0, then jump over return
  
      BE _next          ; if statement by "branch"-cmd
          MOV R0, #0    ; return value is zero
          BX LR         ; always return 0 here
  _next:
  
      sub R0, R0, #1    ; loop counting
      BLPL _for_loop    ; pl = if positive or zero
  
      MOV R0, #1        ;
      BX LR             ; always return 1 here
  
  ENDP
  </code></pre>
  
  <p>but i'm really not sure, if this is right, but i have no idea how to check it....</p>