The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: bozo on September 04, 2008, 12:08:48 AM

Title: sscanf for 64-bit integers?
Post by: bozo on September 04, 2008, 12:08:48 AM
Hey all

I was trying to use sscanf() function to read a 64-bit decimal value from an input box, %llu and %I64d only seemed to return 32-bit value..


qwNumber dq ?
szNumber db "12345678901234"

invoke sscanf,addr szNumber, "%I64d", addr qwNumber


In the end i wrote a simple conversion using mul/add which does work.. but i was wondering if anyone here knew of a function accessable from assembly to do the job without manually written code?
Title: Re: sscanf for 64-bit integers?
Post by: MichaelW on September 04, 2008, 12:40:28 AM
It works for me:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      qwNumber dq 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke crt_sscanf, chr$("9223372036854775807"),
                       chr$("%I64d"), ADDR qwNumber
    invoke crt_printf, chr$("%I64d%c"), qwNumber, 10
    invoke crt_printf, chr$("%I64x%c"), qwNumber, 10
    invoke crt_sscanf, chr$("-9223372036854775808"),
                       chr$("%I64d"), ADDR qwNumber
    invoke crt_printf, chr$("%I64d%c"), qwNumber, 10
    invoke crt_printf, chr$("%I64x%c"), qwNumber, 10
    invoke crt_sscanf, chr$("18446744073709551615"),
                       chr$("%I64u"), ADDR qwNumber
    invoke crt_printf, chr$("%I64u%c"), qwNumber, 10
    invoke crt_printf, chr$("%I64x%c"), qwNumber, 10

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


9223372036854775807
7fffffffffffffff
-9223372036854775808
8000000000000000
18446744073709551615
ffffffffffffffff
Title: Re: sscanf for 64-bit integers?
Post by: bozo on September 04, 2008, 02:12:32 AM
hmm, i'll need to look at it later, i am using CRTDLL.DLL but haven't tried MSVCRT.DLL (if there is difference, don't know)
Title: Re: sscanf for 64-bit integers?
Post by: GregL on September 04, 2008, 05:09:34 AM
Quote... i am using CRTDLL.DLL but haven't tried MSVCRT.DLL (if there is difference, don't know)

CRTDLL.DLL is the older (now defunct) C run-time library, it came with Visual C++ 4.0, Windows 95 and Windows NT. MSVCRT.DLL is the newer C run-time library. It comes with all versions of Windows since Windows 95B. It also came with Visual C++ 6.0. It's a "well known" DLL. I just read the other day that Microsoft is still updating and improving it, the last update was for Windows Vista.


Title: Re: sscanf for 64-bit integers?
Post by: bozo on September 04, 2008, 09:14:01 PM
Yes, that was the problem alright.
Thanks guys, all working now.