Search code examples
gdbnasmyasm

GDB: Printing binary values omits leading zero?


I'm writing some simple assembly programs with the y assembler. However, I've noticed that although I can examine binary values in memory just fine, printing them (in the registers) omits a leading zero. This keeps catching me off guard, and so I'm wondering if there is a reason for it.


Program

    segment .data

f   dd  2.25        ; 32-bit floating point.

    segment .text
    global main

main:
    mov eax, [f]
    xor rax, rax
    ret

GDB

After setting a break point on the line corresponding to mov eax, [f], I get the following binary value using the examine command:

(gdb) x/1tw &f
0x601030:   01000000000100000000000000000000

I have manually verified this. However, the print command yields something different once it is loaded into the eax register:

(gdb) p/t $eax
$2 = 1000000000100000000000000000000

The former is 32 bits, while the latter is 31. The leading zero is omitted. Am I doing something wrong in displaying these values?


Solution

  • Am I doing something wrong in displaying these values?

    No. GDB is inconsistent in its handling of leading zero between the x and the p commands, that's all.

    If you want print to print leading zeros, use p/tz $eax (documentation).