title: ARM assembly recursive power function
body: <p>Need to convert the following C code into ARM assembly subroutine:</p>
  
  <pre><code> int power(int x, unsigned int n) 
   {          
     int y; 
     if (n == 0)  
       return 1; 
     if (n &amp; 1) 
       return x * power(x, n - 1); 
     else 
     { y = power(x, n &gt;&gt; 1); 
       return y * y; 
     } 
   }     
  </code></pre>
  
  <p>Here's what I have so far but cant figure out how to get the link register to increment after each return (keeps looping back to the same point)</p>
  
  <pre><code>pow             CMP             r0, #0
                  MOVEQ           r0, #1
                  BXEQ            lr
                  TST             r0, #1
                  BEQ             skip
                  SUB             r0, r0, #1
                  BL              pow
                  MUL             r0, r1, r0
                  BX              lr
  skip            LSR             r0, #1
                  BL              pow
                  MUL             r3, r0, r3
                  BX              lr
  </code></pre>