title: Comparing in x87 FPU
body: <p>I'm working on a <em>MASM32</em> project, using the x87 instruction set. I want to compare two floating point numbers and print out a message telling the result of the comparison. My program is:</p>
  
  <pre><code>.386
  .model flat, stdcall
  option casemap :none
  include \masm32\include\windows.inc
  include \masm32\include\kernel32.inc
  include \masm32\include\user32.inc
  includelib \masm32\lib\kernel32.lib
  includelib \masm32\lib\user32.lib
  include c:\masm32\include\masm32rt.inc
  .data
      _a DD ?
      _b DD ?
      FP_11_ DD 11.
      FP_10_ DD 10.
  .code
      start:
          MOV ebx, FP_10_
          MOV _a, ebx
          FLD _a
          FCOM FP_11_
          fstsw ax
          sahf
          JGE label5
          print "less", 13, 10, 0
          JMP label6
          label5:
          print "greater", 13, 10, 0
          label6:
          jmp end_program
  
          end_program:
              invoke ExitProcess, 0
      end start
  </code></pre>
  
  <p>The expected result is "less" but i'm getting "greater". So, my question is: how can I compare <strong>correctly</strong> two FP numbers by <code>&lt;=</code>, <code>&gt;=</code>, <code>&lt;</code>, <code>&gt;</code>, <code>==</code> and <code>&lt;&gt;</code> using the x87 instructions?.</p>