title: How to use floating point numbers in x86-64 assembly?
body: <p>I'm struggling with some x86-64 assembly, and floating point numbers are giving me a headache. For instance, when I run this code :</p>
  
  <pre><code>section .data
       omega:  dq 2.0
       omega2: dq 3.0
  
  section .text
  global func
  
  func: push rbp
        mov rgp, rsp
  
        FINIT
  
        FLD qword [omega]
        FLD qword [omega2]
        FADD st0, st0
  
        mov rsp, rbp
        pop rbp
        ret
  </code></pre>
  
  <p>This function is called from a C code like that : <code>printf("%Lf \n", func() );</code>
  Unfortunately the result is some bizarre number... I tried adding two integers using <code>FIADD</code>, and it worked fine. I dug through a ton of material already, but maybe someone here can point me to decent FPU tutorial, or share her/his experience and wisdom :)</p>
  
  <p>Wrapping up the essentials:</p>
  
  <ul>
  <li>language: x86-64 assembler </li>
  <li>assembler: nasm v. 2.09.04 installed from repositories </li>
  <li>compiler (for C): gcc v. 4.5.2 (installed with Ubuntu)</li>
  <li>OS: Ubuntu 11.04 64bit on Oracle VM</li>
  <li>Host OS: Windows 7 SP1 64bit</li>
  <li>Processor: Intel i5 - 2430M 64bit (checked twice :D )</li>
  <li>Problem: FPU can't add two numbers :(</li>
  </ul>
  
  <p>Just in case : in the end i hope to use <code>FSINCOS</code> and other fancy FPU instructions, but seeing as even simple addition fails...</p>
  
  <p>Thanks all in advance!</p>