title: Why does stmfd/ldmfd jump back to sub?
body: <p>I am doing a project for UNI and have a problem.</p>
  
  <p>We are learning how to push/pop registers onto stack when calling a subroutine.</p>
  
  <p>I need to write a subroutine to convert a decimal number 0-15 into a corresponding hex ASCII code, and keep the value of all registers except <code>r0</code>, where the result should be stored. I have a table of ASCII codes, and basically just add the <code>number*4</code> to the starting address of the ASCII table, and store the value back into <code>r0</code>.</p>
  
  <p>I get the right result, but the subroutine loops. It keeps jumping from <code>ldmfd</code> to <code>sub</code> endlessly. Any idea why?   </p>
  
  <pre><code>main:
  adr r0,num
  adr r1,ascii
  ldr r2,[r0]
  bl  sub
  sub:  stmfd sp!,{r1-r2,lr}
        ldr r0,[r1,r2,LSL #2]
        ldmfd sp!,{r1-r2,pc}
  
  /* variables here */
  num:    .word 15
  ascii:  .word 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46
  /* end variables */
  </code></pre>