title: How to save the registers value using inline Assembler
body: <p>(Well,this is the first time i ask questions here and English isn't my first language,so please forgive some of my mistakes. And i'm a green hand in programme.)</p>
  
  <p>I met this problem while doing my OS homework, we were asked to simulate the function <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms686350%28v=vs.85%29.aspx" rel="nofollow">SwitchToFiber</a>,and my current problem is i don't know how to save the registers value in order to recover the function next time it was called.</p>
  
  <p>I don't know if my problem was clear. Though i don't think my code was useful, i will put them below.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define INVALID_THD NULL
  #define N 5
  #define REG_NUM 32
  unsigned store[N][REG_NUM];
  typedef struct
  {
      void (*address) (void * arg);
      void* argu;
  }thread_s;
  
  thread_s ts[N];
  
  void StartThds();
  void YieldThd();
  void *CreateThd(void (*ThdFunc)(void*), void * arg);
  void thd1(void * arg);
  void thd2(void * arg);
  void StartThds()
  {
  
  }
  
  void YieldThd()
  {
      thd2((void*)2);
  
  }
  
  void *CreateThd(void (*ThdFunc)(void*), void * arg)
  {
      ts[(int)arg].address = (*ThdFunc);
      ts[(int)arg].argu = arg;
  }
  
  void thd2(void * arg)
  {
      for (int i = 4; i &lt; 12; i++)
      {
          printf("\tthd2: arg=%d , i = %d\n", (int)arg, i);
          //in order to see clearly，i added /t abouve
          YieldThd();
      }
  }
  
  void thd1(void * arg)
  {
  /* 
      __asm__(
  
      );
  */ 
      for (int i = 0; i &lt; 12; i++)
      {
          printf("thd1: arg=%d , i = %d\n", (int)arg, i);
          YieldThd();
      }
  }
  
  int main()
  {
      //this is my first plan, to store the register value in some static arry 
      for(int i = 0; i&lt;N; i++)
          for(int j = 0; j&lt;REG_NUM; j++)
              store[i][j] = 0;
      //create the two thread 
      if (CreateThd(thd1, (void *)1) == INVALID_THD)
      {
          printf("cannot create\n");
      }
      if (CreateThd(thd2, (void *)2) == INVALID_THD)
      {
          printf("cannot create\n");
      }
  
  
      ts[1].address(ts[1].argu);      //thd1((void*)1),argu = 1； 
  //  StartThds();
      return 0;
  }
  </code></pre>
  
  <p>This is the whole code now i have,because i don't know which part maybe useful, so i put them all above. As you can see, most of them are still empty.</p>