title: ARM Thumb-2, GCC, code changes, and the `stmdaeq` instruction
body: <p>I'm using and STM32F4 (Cortex-M4) MCU and compiling with arm-none-eabi-g++ (I'm using C++).</p>
  
  <p>I have a requirement to reduce the amount of time it takes to upload my binary to the MCUs flash memory.  I have figured out I can do this by only uploading changes to my binary between modifications.  However, the compiler is generating some interesting code that is making this impossible.</p>
  
  <p>Consider the following 2 programs:</p>
  
  <p>(1)</p>
  
  <pre><code>int main()
  {
      printf("hello");
      return 0
  }
  </code></pre>
  
  <p>(2)</p>
  
  <pre><code>int main()
  {
      //printf("hello");
      return 0
  }
  </code></pre>
  
  <p>By simply removing the <code>printf</code> call, the binary is drastically different.  I can see this by disassembling the code using <code>arm-none-eabi-objdump -D mybinary</code>.  Here's a sample of the differences in WinMerge:</p>
  
  <p><img src="https://i.stack.imgur.com/o5vlp.png" alt="enter image description here"></p>
  
  <p>As can be seen in the image, almost all functions have a slightly different <code>stmdaeq</code> instruction, and I want to know more about this.</p>
  
  <p>An answer to this question will include the following:</p>
  
  <ul>
  <li>I know what the <code>stmdaeq</code> instruction is, but why is it at the end of nearly all functions?  Is this the function's epilogue?</li>
  <li>Is there anything I can do (compiler options or otherwise) to ensure that minor code changes, like my example above, don't cause such changes throughout the entire binary?</li>
  </ul>
  
  <p>I'm using the <a href="https://launchpad.net/gcc-arm-embedded" rel="nofollow noreferrer">GNU Tools for ARM Embedded Processors</a> GCC toolchain.</p>
  
  <p>Your help will be most appreciated.</p>