format - assembly printf call printing wrong value -


at point in code know eax contains 12345678 (says in debugger)

    push    eax     push    print_r     call    printf     add     esp, 8 

my format string is

print_r:    db 0ah, "number: %hd", 10, 0 

instead of printing 12345678, prints 24910

when eax contains 1234 however, correctly prints 1234

i have feeling has string formating %hd, don't know make can print reguardless of how big/ sign number is.

this because use %hd printing. %hd takes 16b value , print it, provide 32b values.

what happening: value 12345678 means 0xbc614e. because use %hd, printf consider 16b form number (number truncated 16b) , value printed 0x614e printed value: 24910.

2 possible fixed:

  • replace printf format "%hd" "%d"
  • use printing number on 16b (between -32769 , 32768).

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -