title: GDB - Print floating point value from assembly
body: <p>I have the following code, where <code>b</code> is initialized to the floating point value <strong>123.45</strong>:</p>
  
  <pre><code>global _start
  
  section .data
  
      ;a : dw 999     ; declare word
      b : dq 123.45  ; declare quad word (double precision)
  
  section .bss
  
      res : resq 1   ; reserve 1 quad word for result
  
  section .text
  
      _start :
  
          nop
  </code></pre>
  
  <p>I create an object (sanityTest.o) file and an executable file (sanityTest) as follows. I am running on a x64 machine:</p>
  
  <pre><code>nasm -f elf64 -F dwarf -g sanityTest.asm -o sanityTest.o
  
  ld -m elf_x86_64 -o sanityTest sanityTest.o
  </code></pre>
  
  <p>I then attempt to read the value of <code>b</code> in gdb as follows:</p>
  
  <pre><code>(gdb) file sanityTest
  Reading symbols from sanityTest...done.
  (gdb) break _start
  Breakpoint 1 at 0x4000b0
  (gdb) run
  Starting program:
  Breakpoint 1, 0x00000000004000b0 in _start ()
  (gdb) print b
  $1 = -858993459
  (gdb) print/f b
  $2 = -107374184
  (gdb)
  </code></pre>
  
  <p>Why does neither <code>print b</code> nor <code>print/f b</code> display the value <strong>123.45</strong>?</p>
  
  <p><br>
  <strong>More information:</strong></p>
  
  <p>If I compile the code with the line <code>b : dq 123.45</code> commented out, and the line <code>a : dw 999</code> uncommented, I am able to print the integer value of <code>a</code> of <strong>999</strong>:</p>
  
  <pre><code>(gdb) p a
  $1 = 999
  </code></pre>
  
  <p>If I compile with both lines uncommented, I can print neither <code>a</code> nor <code>b</code>. The value for <code>b</code> is the same gibberish as before, and I have no idea what is now being printed for <code>a</code>:</p>
  
  <pre><code>(gdb) p a
  $1 = -858979353
  (gdb) p b
  $2 = -858993459
  (gdb) p/f a
  $3 = -107487032
  (gdb) p/f b
  $4 = -107374184
  </code></pre>