title: How to print a single-precision float with printf
body: <p>I'm trying to print a floating point number in x86_64 assembly but it just prints the value as zero.</p>
  
  <p>There's a few questions about this already. One appeared to be resolved by ensuring that <a href="https://stackoverflow.com/q/20594800/331041">you set the number of vector registers you're using in %al</a>. Another showed that <a href="https://stackoverflow.com/q/26839444/331041">you need to have a stack alignment of 16 bytes</a>. But, I'm doing both those things and still not getting correct output.</p>
  
  <p>This is my program:</p>
  
  <pre><code># prints a floating point value
  .section .rodata
  .fmt: .string "num: %f\n"
  .num: .float 123.4
  
  .section .text
  .global main
  .type   main, @function
  main:
    subq $8, %rsp     # 16-byte alignment
  
    # print my number
    movss .num, %xmm0 # load float value
    movq $.fmt, %rdi  # load format string
    movb $1, %al      # use 1 vector register
    call printf
  
    # exit
    addq $8, %rsp     # undo alignment
    movq $0, %rax     # return 0
    ret
  </code></pre>