title: MSP430 Assembly Stack Pointer Behavior
body: <p>While trying to analyze a simple Assembly file generated through the msp430-gcc, I stumbled upon a set of instructions that I don't understand dealing with the frame pointer and the MSP430's stack pointer.</p>
  
  <p>C Program:</p>
  
  <pre><code>#include "msp430g2553.h"
  
  int main()
  {
    int i;
  
    for(i = 0; i &lt; 3; i++);
  
  }
  </code></pre>
  
  <p>Assembly minus directives:</p>
  
  <pre><code>main:
          mov     r1, r4 ;Stores address of stack pointer in r4(frame pointer)
          add     #2, r4 ; ?
          sub     #2, r1 ; subtract 2 to allocate int i
          mov     #0, -4(r4) ; assign 0 to i
          jmp     .L2 ; start loop
  .L3:
          add     #1, -4(r4) ; Adds one to int i
  .L2:
          cmp     #3, -4(r4) ; Compare to #3
          jl      .L3 ; jump to .L3 if true
          add     #2, r1 ; deallocate int i
  .Lfe1:
          .size   main,.Lfe1-main
  </code></pre>
  
  <p>I tried commenting the code to trace the program's execution, but I don't understand the line <code>add #2, r4</code>. What exactly is happening here, and why is <code>int i</code> being referenced at <code>-4(r4)</code>?</p>