title: Assembly IA32: Move 4 byte float from stack to FPU
body: <p>At my university we are introduced to IA32/x86 assembler with AT&amp;T Syntax. But the explanation lacks of important information.</p>
  
  <p>How am I able to move a 4 byte float from the stack to the FPU? I tried with flds but it didn't work as expected...</p>
  
  <p>EXAMPLE CODE:</p>
  
  <pre><code>.data
          fl:     .float 12.412
          test:   .string "Result: %f\n"
  
  .text
  .global main
  
  main:
          # Prepare the stack (8 byte so i can use it for printf later)
          subl $8, %esp
          # Load the variable fl which holds 12.412
          fld fl
          # Store the previously loaded value as single precision (4 byte) to the stack
          fstps (%esp)
          # Load the value from the stack again and expect it to be single precision (as flds ends with s)
          flds (%esp)
  
  
          # Push it to the stack again. But this time as double precision value als printf expects floats to be 8 bytes long 
          fstp (%esp)
          pushl $test
          call printf
  
          movl $1, %eax
          int $0x80
  </code></pre>
  
  <p>But the output is:</p>
  
  <p><strong>Result: -0.491594</strong></p>
  
  <p>and not 12.412 as expected...</p>
  
  <p><strong>[EDIT:] Funny fact. Surprisingly the result changes for every single execution of the program.</strong></p>