flat assembler
Message board for the users of flat assembler.

Index > Windows > convert dq to asc integer

Author
Thread Post new topic Reply to topic
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 13 Sep 2011, 17:20
Hi,

I don't want to go and re-invent the wheel. I generate some dq unsigned integers and want to save them to file as ascii base 10 numbers

i.e. 0x123456789ABCDEF0 -> 0x31, 0x33, 0x31, 0x31, 0x37, 0x36, 0x38, 0x34, 0x36, 0x37, 0x34, 0x36, 0x33, 0x37, 0x39, 0x30, 0x33, 0x32, 0x30

so that the file reads 1311768467463790320

can someone point me to either an existing function or a method for doing it without the fpu?

thanks

magicĀ²
Post 13 Sep 2011, 17:20
View user's profile Send private message Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat 13 Sep 2011, 17:30
Windows's printf function can do this; the %I64u format prints an unsigned 64-bit integer.
Post 13 Sep 2011, 17:30
View user's profile Send private message Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 13 Sep 2011, 17:39
thanks for the quick reply Wink

can it do this to file ?

I don't know the syntax of printf in fasm

If my value was stored in dq mVal and the file was myFile how would I write it?

thanks again
Post 13 Sep 2011, 17:39
View user's profile Send private message Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 13 Sep 2011, 18:41
It's ok now.

Think I had brain-freeze.

Couldn't think how I could divide qword, lol

Code:

myVal   dq 0x5943DD1690A03A14           ; 6432227781800638996
buff    db 30 dup ?

        mov     eax, dword [myVal+4]
        mov     ebx, dword [myVal]
        mov     ecx, 10
        xor     edx, edx
        mov     edi, buff+28
        mov     byte [edi+1], 0         ;zero terminator
    @@:
        div     ecx
        xchg    eax, ebx
        div     ecx
        xchg    eax, ebx
        add     dl, 0x30
        mov     [edi], dl
        xor     dl, dl
        dec     edi
        or      eax, eax
        jnz     @b
        or      ebx, ebx
        jnz     @b
        inc     edi
        int3
    


I'm sure you can all write it more succinctly, but it works for my needs :O)
Post 13 Sep 2011, 18:41
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.