title: Setting the stack pointer in AVR microcontrollers with C code
body: <p>It is known that in AVR microcontrollers the stack pointer decreases for each element added to the stack. I want to reserve memory for a new task stack, and I use </p>
  
  <pre><code>unsigned char *pS = (unsigned char*)malloc(64*sizeof(unsigned char));
  </code></pre>
  
  <p>This I think returns a pointer to <em>the beginning</em> of an area in SRAM followed by 64 bytes, therefore for setting the stack pointer at the new stack I use</p>
  
  <pre><code>SP = (unsigned int)pS + 64
  </code></pre>
  
  <p>Is this correct?</p>