I am using gdb to examine a program. In assembly, the code is doing:
cmp $0x5, %eax
However, when I examine the contents of %eax
, I get: \020\343\377\377\377\177
when examined as a string.
How is \020\343\377\377\377\177
compared to $0x5 in assembly?
cmp
, in this case, is comparing the value ineax
to a constant5
. The value pointed to byeax
, if you think it is in fact a pointer, isn't compared to the constant at all.The comparison is done by subtraction - in your case, that means
5
is subtracted from the value ineax
, and several flags (CF, OF, SF, ZF, AF, and PF, according to the documentation) are set appropriately. Normally thecmp
instruction is followed by a conditional instruction of some kind (often a jump), to perform different actions depending on the results of the comparison.If you tell us the value in
eax
, rather than interpretingeax
as a pointer, I might be able to give you some more information. You can usep $eax
orinfo registers
to get the value ofeax
in gdb.