title: x87 FPOP and FCOM instructions - how do these work?
body: <p>I've been tasked with writing a simple application in mixed C/ASM that has to use math coprocessor. </p>
  
  <p>There's the function cylinder(float x,  float y, float z) that returns 1 if the given point is within the cylinder (the cylinder has a base at x=0,y=0, radius = 5 and height = 10), and 0 if it isn't.</p>
  
  <p>So, looks simple. Check whether z is within &lt;0,10>, and then check if x^2 + y^2 &lt; 25.</p>
  
  <p>But my knowledge about x87 is nil.</p>
  
  <p>There's everything I've written. </p>
  
  <pre><code>_cylinder PROC
  
  push ebp
  mov ebp, esp
  sub esp,8 ; I can't use .data in the application, so I reserve some space on the stack for numbers 10 and 25
  mov [esp],10
  mov [esp+4],25
  
  finit
  fldz
  fld [ebp+8]
  
      ;here i get stuck 
  
  add esp, 8
  pop ebp
  _cylinder ENDP
  </code></pre>
  
  <p>So I got stuck. So, I try to find what instructions could I use in the application. And there I get stuck, because every tutorial/instruction list i find on the net is written so badly I can barely understand anything. </p>
  
  <p>The question is, what happens when I pop something from the math coprocessor? Where can I find the popped value? How does it converts from 80-bit value to 32 bit one (if it does, of course)
  Another question is, how does the FCOM (FCOMP for pop variant) works? It compares what to what ( st0 to st1 or st1 to st0?), and where can I see whether the value is smaller/equal/bigger?</p>
  
  <p>Thanks for any help!</p>