title: Why will I have operand type mismatch error when compiling the assembly codes with gcc?
body: <p>The following codes are used for calculate the <code>sin</code> and <code>cos</code> value if the angle is given. In order to  calculate these functions as fast as possible, assembly code implementations are adopted. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  float sinx( float degree ) {
      float result, two_right_angles = 180.0f ;
      __asm__ __volatile__ ( "fld %1;"
                              "fld %2;"
                              "fldpi;"
                              "fmul;"
                              "fdiv;"
                              "fsin;"
                              "fstp %0;" 
                              : "=g" (result) 
                              : "g"(two_right_angles), "g" (degree)
      ) ;
      return result ;
  }
  
  float cosx( float degree ) {
      float result, two_right_angles = 180.0f, radians ;
      __asm__ __volatile__ ( "fld %1;"
                              "fld %2;"
                              "fldpi;"
                              "fmul;"
                              "fdiv;"
                              "fstp %0;" 
                              : "=g" (radians) 
                              : "g"(two_right_angles), "g" (degree)
      ) ;
      __asm__ __volatile__ ( "fld %1;"
                              "fcos;"
                              "fstp %0;" : "=g" (result) : "g" (radians)
      ) ;
      return result ;
  }
  
  float square_root( float val ) {
      float result ;
      __asm__ __volatile__ ( "fld %1;"
                              "fsqrt;"
                              "fstp %0;" 
                              : "=g" (result) 
                              : "g" (val)
      ) ;
      return result ;
  }
  
  int main() {
      float theta ;
      printf( "Enter theta in degrees : " ) ;
      scanf( "%f", &amp;theta ) ;
  
      printf( "sinx(%f) = %f\n", theta, sinx( theta ) );
      printf( "cosx(%f) = %f\n", theta, cosx( theta ) );
      printf( "square_root(%f) = %f\n", theta, square_root( theta ) ) ;
  
      return 0 ;
  }
  </code></pre>
  
  <p>The above codes comes from <a href="http://www.codeproject.com/Articles/15971/Using-Inline-Assembly-in-C-C" rel="nofollow">here</a>, and I am trying to compile the above codes with gcc:</p>
  
  <pre><code>g++ -Wall -fexceptions  -g     -c /filename.cpp  
  </code></pre>
  
  <p>However, it fails, and the following error messages are given:</p>
  
  <pre><code>Error: operand type mismatch for `fstp'|
  Error: operand type mismatch for `fstp'|
  </code></pre>
  
  <p>I was wondering why the compilation would fail and how I can compile them successfully. Thanks! </p>