flat assembler
Message board for the users of flat assembler.

Index > Main > dword to ascii, ascii to dword

Goto page Previous  1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 13100
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 09 Feb 2013, 19:07
i reupload it already (just in case you haven't notice)
i use vbs script to generate the input file fyi,

and 10,000 seems to fast to process, my time is 0 millisecond used.. omG, now i generate a 1,000,000, but my time is still 0 millisecond,

maybe i should use something else to measure?

here is my algo
Code:
; input :       asciiAddr = ascii string number starting address / pointer
; output :      EAX = holding translate number
;                       ECX = 0 (signed) 1 (unsigned)
proc sleepsleep_ascii2d uses ebx esi edi, asciiAddr
                        mov  eax,[asciiAddr]
                        mov  edi,_tbl
                        dec  eax
                        xor  ecx,ecx
        @@:
                        inc  eax
                        inc  ecx
                        cmp  byte [eax],0
                        jne  @b
                        sub  ecx,2
        ; ecx got length now
                        
                        mov  ebx,[asciiAddr]
                        xor  eax,eax
                        xor  esi,esi    ; hold total
                        mov  al, [ebx+ecx]
                        sub  al,'0'
                        add  esi,eax
        @@:
                        dec  ecx
                        cmp  ecx,0
                        je   .checkNegative
                        add  edi,4
                        xor  eax,eax
                        mov  al,[ebx+ecx]
                        sub  al,'0'
                        mul  dword [edi]
                        add  esi,eax
                        jmp  @b
                        
        .checkNegative:
                        xor  eax,eax
                        mov  al,[ebx]
                        cmp  al,'-'
                        je   .negativeFound
                        add  edi,4
                        sub  al,'0'
                        mul  dword [edi]
                        add  eax,esi
                        inc  ecx
                        ret
                        
                .negativeFound:
                        mov  eax,esi
                        neg  eax
                        ret

_tbl    dd 0
                dd 10
                dd 100
                dd 1000
                dd 10000
                dd 100000
                dd 1000000
                dd 10000000
                dd 100000000
                dd 1000000000
endp
    
Post 09 Feb 2013, 19:07
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 09 Feb 2013, 19:21
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:38; edited 2 times in total
Post 09 Feb 2013, 19:21
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13100
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 09 Feb 2013, 19:22
i think i found where the problem,
ok, here the output for 1,000,000 unique string number

1,000,000 unique string number input could be downloaded from here (5.28 MB)
http://www.sinimari.com/ascii.7z

Quote:


D:\FASM\PROJECT>fasm algobm.asm
flat assembler version 1.70.03 (1295442 kilobytes memory)
4 passes, 6.4 seconds, 10993152 bytes.

D:\FASM\PROJECT>algobm.exe
Benchmark Console
millisecond used to process : 78

D:\FASM\PROJECT>algobm.exe
Benchmark Console
millisecond used to process : 78

D:\FASM\PROJECT>algobm.exe
Benchmark Console
millisecond used to process : 78


modify ESI if you don't want to run 1,000,000 unique string number
Code:
                        mov  esi,1000000
                        mov  ebx,string1

        ascii2d_start:
                        cmp  esi,0
                        je   ascii2d_end
                        
        stdcall sleepsleep_ascii2d,ebx
                        dec  esi
        @@:
                        inc  ebx
                        cmp  byte [ebx], 0
                        jne  @b
                        inc  ebx
                        jmp  ascii2d_start
        
        ascii2d_end:
        invoke  GetTickCount
                        mov  ecx,[_starttime]
                        sub  eax,ecx

    


Description: source file
Download
Filename: algobm.asm
Filesize: 2.75 KB
Downloaded: 333 Time(s)



Last edited by sleepsleep on 09 Feb 2013, 19:31; edited 1 time in total
Post 09 Feb 2013, 19:22
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13100
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 09 Feb 2013, 19:28
HaHaAnonymous wrote:
I have to follow the rules of registers preservation or it just needs to use the "stdcall" calling convention?

The function itself must process one string at a time or a given range?


stdcall, preserve ESI, EBX, EDI

replace my function to your function
Code:
stdcall sleepsleep_ascii2d,ebx
    


as i already perform the loading ascii string for you, so everybody would use same loading time.

please note that, you need to download 1,000,000 input file if you want to test,

but maybe i should make one 10,000,000 input file, the time is too fast.

i think, maybe something wrong with my GetTickCount, you guys please advice,

i tried 2,000,000 input, still 78... damn it.


Last edited by sleepsleep on 09 Feb 2013, 19:39; edited 1 time in total
Post 09 Feb 2013, 19:28
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 09 Feb 2013, 19:37
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:38; edited 3 times in total
Post 09 Feb 2013, 19:37
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13100
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 09 Feb 2013, 19:42
AsmGuru62 wrote:
@2sleep: also how the code called must be defined.
Is it a function? or just piece of code to copy/paste?
If it is a function - what is calling convention?

Also, GetTickCount() is a bad way to measure the code speed.
Use QueryPerformanceTimer() instead.


ok,
maybe we should use QueryPerformanceTimer,

please donate code Cool
this would be a fun game for everybody
Post 09 Feb 2013, 19:42
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 09 Feb 2013, 19:49
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:37; edited 1 time in total
Post 09 Feb 2013, 19:49
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 09 Feb 2013, 20:07
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:37; edited 3 times in total
Post 09 Feb 2013, 20:07
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1678
Location: Toronto, Canada
AsmGuru62 10 Feb 2013, 00:10
@2sleep: you're should be the one to test all our code!
We send our code and you hook it up to the same testing code on
the same (yours) system. And measure with QueryPerformanceCounter.
Then it would be somewhat interesting.

And your test file has invalid strings - some values are out of range.

P.S. I can code the testing framework and send it to you.
You just call everyone's function and report results.
Post 10 Feb 2013, 00:10
View user's profile Send private message Send e-mail Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13100
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 10 Feb 2013, 00:37
ok =) asmguru, no problem =)

regarding the out of range, the 1,000,000 5mb file shouldnt have those values, or am i wrong?

thanks haha,
let see how those proc benchmark later =)
Post 10 Feb 2013, 00:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20482
Location: In your JS exploiting you and your system
revolution 10 Feb 2013, 00:56
Hmm, I'm still struggling to imagine a situation where I need to do millions upon millions of ASCII/dword conversions per second, and do them hyper-quickly, else my program will fail and be unusable. Question
Post 10 Feb 2013, 00:56
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1678
Location: Toronto, Canada
AsmGuru62 10 Feb 2013, 15:00
It usually needed for reporting/scanning software.
Imagine that you need to return results from SQL a query into a TXT file.
If result set is large (into thousands of rows and every cell is a value), so you get a huge file with numbers.
Then you need to read that file and do some sub-queries on these values (which are now ASCII values).

Can be other cases where you need to read and process a lot of ASCII Integer values.
Of course, your code will not fail or be unusable, but it will process a lot of info more slowly,
than other, more optimized solution.

Besides, measuring the code speed is interesting in a way that sometimes it gives unexpected results.
Post 10 Feb 2013, 15:00
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20482
Location: In your JS exploiting you and your system
revolution 11 Feb 2013, 02:57
AsmGuru62 wrote:
It usually needed for reporting/scanning software.
Imagine that you need to return results from SQL a query into a TXT file.
If result set is large (into thousands of rows and every cell is a value), so you get a huge file with numbers.
Then you need to read that file and do some sub-queries on these values (which are now ASCII values).

Can be other cases where you need to read and process a lot of ASCII Integer values.
Of course, your code will not fail or be unusable, but it will process a lot of info more slowly,
than other, more optimized solution.
Somehow I suspect that the SQL engine will be the major bottleneck here. Also if you are reading/writing this processed data to/from disk then that would be a much better place for optimising by using streaming methods. The CPU will outstrip the disk speed by many orders of magnitude.
AsmGuru62 wrote:
Besides, measuring the code speed is interesting in a way that sometimes it gives unexpected results.
This sounds like a much more plausible reason to me. I can imagine a situation where someone codes up the "fastest possible" converter and still finds that the overall speed improvement is minimal and discovers the real cause of the slowness is something else completely. Twisted Evil
Post 11 Feb 2013, 02:57
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13100
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 11 Feb 2013, 03:43
it is a game,
please play, revolution,

=)
for fun, and experience =P
Post 11 Feb 2013, 03:43
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
uart777 11 Feb 2013, 04:45
Here's a runtime macro that converts a byte to hexadecimal text fast. An "itoa" function could use this if n<256. It takes an extra 512 bytes so it may only be worthwhile for certain programs that require the fastest number-text conversions; scripting languages, disassemblers.

Code:
; let eax=n, eax&0FFh, edx=&[hbt+eax*2],\
; cx=[edx], eax=t, [eax]=cx, eax+2, byte [eax]=0

macro hb2t n, t {
mov eax, n
and eax, 0FFh        ; ensure 0-255
lea edx, [hbt+eax*2]
mov cx, [edx]
mov eax, t
mov [eax], cx
add eax, 2           ; return advanced address
mov byte [eax], 0    ; terminate t
}

; h byte lookup table (512 bytes)

hbt: db \
'00','01','02','03','04','05','06','07',\
'08','09','0A','0B','0C','0D','0E','0F',\
'10','11','12','13','14','15','16','17',\
'18','19','1A','1B','1C','1D','1E','1F',\
'20','21','22','23','24','25','26','27',\
'28','29','2A','2B','2C','2D','2E','2F',\
'30','31','32','33','34','35','36','37',\
'38','39','3A','3B','3C','3D','3E','3F',\
'40','41','42','43','44','45','46','47',\
'48','49','4A','4B','4C','4D','4E','4F',\
'50','51','52','53','54','55','56','57',\
'58','59','5A','5B','5C','5D','5E','5F',\
'60','61','62','63','64','65','66','67',\
'68','69','6A','6B','6C','6D','6E','6F',\
'70','71','72','73','74','75','76','77',\
'78','79','7A','7B','7C','7D','7E','7F',\
'80','81','82','83','84','85','86','87',\
'88','89','8A','8B','8C','8D','8E','8F',\
'90','91','92','93','94','95','96','97',\
'98','99','9A','9B','9C','9D','9E','9F',\
'A0','A1','A2','A3','A4','A5','A6','A7',\
'A8','A9','AA','AB','AC','AD','AE','AF',\
'B0','B1','B2','B3','B4','B5','B6','B7',\
'B8','B9','BA','BB','BC','BD','BE','BF',\
'C0','C1','C2','C3','C4','C5','C6','C7',\
'C8','C9','CA','CB','CC','CD','CE','CF',\
'D0','D1','D2','D3','D4','D5','D6','D7',\
'D8','D9','DA','DB','DC','DD','DE','DF',\
'E0','E1','E2','E3','E4','E5','E6','E7',\
'E8','E9','EA','EB','EC','ED','EE','EF',\
'F0','F1','F2','F3','F4','F5','F6','F7',\
'F8','F9','FA','FB','FC','FD','FE','FF' 

; example with my Z77 library...

include 'z.inc'
use hbyte

TEXT t(64), f(32)='Result: %th', tn(4)

code
hb2t 07Fh, tn
print t, f, tn
say t
exit    
Post 11 Feb 2013, 04:45
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 11 Feb 2013, 05:31
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:35; edited 1 time in total
Post 11 Feb 2013, 05:31
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 11 Feb 2013, 05:41
I like games Smile
Here is my procedure. It is named "Dec2Num" because it converts decimal numbers (only unsigned) from ASCII to dword. Also, it does not check the string for invalid characters (should it?):
Code:
UDec2Num:
        mov     ecx, [esp+4]

        xor     edx, edx
        xor     eax, eax

.loop:
        mov     dl, [ecx]
        inc     ecx
        test    dl, dl
        jz      .ends

        lea     eax, [5*eax]
        sub     dl, '0'
        shl     eax, 1
        add     eax, edx
        jmp     .loop

.ends:
        retn 4    


Last edited by JohnFound on 11 Feb 2013, 07:13; edited 2 times in total
Post 11 Feb 2013, 05:41
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 11 Feb 2013, 05:50
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:34; edited 1 time in total
Post 11 Feb 2013, 05:50
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 11 Feb 2013, 06:07
[EDIT] See my next posts - there is a faster implementation of this algorithm.[/EDIT]
Ah, OK, I will fix it. Just a second:
Code:
johnfound_ascii2d:
        xor     eax, eax
        xor     ecx, ecx
        xor     edx, edx
        xchg    ecx, [esp+4]

        cmp     byte [ecx], '-'
        jne     .loop
        inc     ecx
        dec     dword [esp+4]
.loop:
        mov     dl, [ecx]
        inc     ecx
        test    dl, dl
        jz      .ends

        lea     eax, [5*eax]
        sub     dl, '0'
        shl     eax, 1
        add     eax, edx
        jmp     .loop

.ends:
        xor     eax, [esp+4]
        sub     eax, [esp+4]
        retn 4    


[EDIT]Fixed name and STDCALL convention. Code cleanup.[/EDIT]


Last edited by JohnFound on 11 Feb 2013, 09:38; edited 4 times in total
Post 11 Feb 2013, 06:07
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 11 Feb 2013, 06:14
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:34; edited 1 time in total
Post 11 Feb 2013, 06:14
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4  Next

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.