title: ARM Assembly question (there is not enough register!)
body: <p>Hi I’m trying to write code that do pattern search, and rank top3 most popular patterns, and how many times it counts patterns.
  I can make code which ranks top2 patterns. but i can't do rank3 one.</p>
  
  <p>(I allocated registers in this way)<br>
      R7 : count of top1 pattern<br>
      R8 : top1 pattern<br>
      R10 : count of top2 pattern<br>
      R11 : top2 pattern    </p>
  
  <p>this is my actual code that works  </p>
  
  <pre><code>void ex3(){
  int result[4];
  
  example3(0x00,0x100, 0x0, result);
  sendstr("Top 1 pattern : ");
  printDecimal(result[0]);
  sendstr("\n");
  
  sendstr("Top 1 pattern count : ");
  printDecimal(result[1]);
  sendstr("\n");
  
  sendstr("Top 2 pattern : ");
      printDecimal(result[2]);
  sendstr("\n");
  
      sendstr("Top 2 pattern count : ");
  printDecimal(result[3]);
  sendstr("\n");
  
  }
  
  
  PRESERVE8
  AREA Ex3, CODE, READONLY
  
  EXPORT  example3
  
  example3
      STMFD       sp!,{r4-r9,lr}              
      MOV         R4, r2                          
      MOV         R6, R3
      MOV         R7, #0
      MOV         R8, #0
  
  Loop2   
      MOV         r3, #0                          
      MOV         r9, r0
  
  Loop
      LDRB        r5, [r9], #1                        
      CMP         r4, r5                          
      ADDEQ       r3, r3, #1                      
      CMP         r9, r1                          
      BLS         Loop
      CMP         R3, R7
      BLT         Com2
  
  
  
  
  Com1
  
      MOVGT   R10,R7
      MOVGT   R11,R8
      MOVGT   R7, R3                          
      MOVGT   R8, R4
      B               Here
  
  Com2
      CMP         R3,R10
      BLT         Here
      MOVGT   R10,R3
      MOVGT   R11,R4
  
  
      CMP         R4, #0XFF
      ADDLT       R4, R4, #1
      BLT         Loop2
  
      STR         r8, [r6]
      STR         r7, [r6,#4]
  
      STR         r11, [r6,#8]
      STR         r10, [r6,#12]
  
  
      LDMFD       sp!,{r4-r9,lr}
  
      MOV         PC, lr
  
      END
  </code></pre>
  
  <p>but when i tried rank3 codes with same logic, just changed register allocation in this way   </p>
  
  <pre><code>r7 count of top1 pattern  
  r8 top1 pattern    
  
  r9 top2 count  
  r10 TOP2    
  
  r11 top3 count  
  r12 top3    
  </code></pre>
  
  <p>it shows strange result because of (in my think) wrong register allocate(I need more empy register...). what is easy way or right way to solve register Lack?    </p>
  
  <pre><code>PRESERVE8
  AREA Ex3, CODE, READONLY
  
  EXPORT  example3
  
  example3
      STMFD       sp!,{r4-r9,lr}              
      MOV         R4, r2                          
      MOV         R6, R3
      MOV         R7, #0
      MOV         R8, #0
  
  Loop2   
      MOV         r3, #0                          
      MOV         r9, r0
  
  Loop
      LDRB        r5, [r9], #1                        
      CMP         r4, r5                          
      ADDEQ       r3, r3, #1                      
      CMP         r9, r1                          
      BLS         Loop
      CMP         R3, R7
      BLT         Com2
  
  
  
  
  Com1
      MOVGT   R11,R9
      MOVGT   R12,R10
      MOVGT   R9,R7
      MOVGT   R10,R8
      MOVGT   R7, R3                          
      MOVGT   R8, R4
      B               Here
  
  Com2
      CMP         R3,R9
      BLT         Com3
      MOVGT   R11,R9
      MOVGT   R12,R10
      MOVGT   R9,R3
      MOVGT   R10,R4
      B               Here
  
  
  Com3
      CMP         R3,R11
      MOVGT   R11,R3
      MOVGT   R12,R4
  
  
  Here
      CMP         R4, #0XFF
      ADDLT       R4, R4, #1
      BLT         Loop2
  
      STR         r8, [r6]
      STR         r7, [r6,#4]
  
      STR         r10, [r6,#8]
      STR         r9, [r6,#12]
      STR         r12, [r6,#16]
      STR         r11, [r6,#20]
  
  
      LDMFD       sp!,{r4-r9,lr}
  
      MOV         PC, lr
  
      END
  </code></pre>