title: inline assembly in avr
body: <pre><code>void save_context(uint8_t index) {
      context *this_context = contextArray + index;
      uint8_t *this_stack = this_context-&gt;stack;
  
  
      asm volatile("st %0 r0":  "r"(this_stack));
  }
  </code></pre>
  
  <p>I have something like this. </p>
  
  <p>!!! I would like to store the registers r0 r1 r2... into my  stack[] array.</p>
  
  <p>What I am programming is the context switch. The context has the structure like this:</p>
  
  <pre><code>typedef struct context_t {
     uint8_t stack[THREAD_STACK_SIZE];
     void *pstack;
     struct context_t *next;
  }context;
  </code></pre>
  
  <p>My problem is that I am not able to pass the c variable "this_stack" to inline assembly. My aim is to store all the registers, stack pointer and SREG on my stack.</p>
  
  <p>After compiling, it gives error:
  Description Resource    Path    Location    Type</p>
  
  <pre><code>`,' required    5_multitasking      line 754, external location: C:\Users\Jiadong\AppData\Local\Temp\ccDo7xn3.s C/C++ Problem
  </code></pre>
  
  <p>I looked up the avr inline assembly tutorial. But I don't quite get a lot.
  Could anyone help me?</p>