im not sure if this one works, i just wrote this down and i hope it works. save this file as "dw2str.asm" and save the declaration somewhere in a header file. i tried to optimize this function so hard because it is a real algorithm where you can do alot and because i wanted to see how far i can go. for nothing else. not for the speed or size. just imagine you call this one in a game ~100 times per sec. who cares if you save 100*200=20000 cycles per sec? if you have any other interesting algorithms that can be optimized, please put them into the msgboard so ppl can work on them. it was fun to do this one and im satisfied w/ the result. regards vineon This message was edited by vineon, on 4/4/2001 12:37:30 PM
.386 .MODEL FLAT, STDCALL comment $ ASSUMES STDCALL !! As for speed reasons, the proc needs all 10 bytes needed for the longest number (1234567890). the return value in eax is the ptr to the first digit: example: .. .DATA? align 32 ;extremely important for speed (this is the most important line you can make using this proc!) digits CHAR 10 dup (?) ;you need 10 digits, regardless of whether you have just a "5" to convert or not. or change the code below, but then it would be static. BYTE ? ;delimiter. initialize this one once to 0. .CODE invoke dw2str, 12345, OFFSET digits ;eax = PTR to the "1" in digits header file: dw2str proto stdcall numbertoconvert : DWORD, ptrwheretosave : PTR CHAR $ ; if you want a real stdcall-proc that saves esi and edi (+~2cycles) REALSTDCALL = 1 ; if you want speed. registers esi edi are destroyed (-~2cycles) ;REALSTDCALL = ; if you want that he sets all digits that are not used to "0" (+~2cycles) (eg 0000000001) SETZERO = 1 ; if you access the digits via eax or if you want speed (-~2cycles) (eg 22222221 where the "2"s are from the conversion from the last dw2str) ;SETZERO = .CODE align 32 upperret: mov eax, esi if REALSTDCALL pop edi pop esi endif ret 8 ;if REALSTDCALL ;dw2str proc uses esi edi numbertoconvert : DWORD, ptrwheretosave : PTR CHAR ;else ;dw2str proc numbertoconvert : DWORD, ptrwheretosave : PTR CHAR ;endif dw2str proc ;number = 4 ;ptr = 8 mov eax, if REALSTDCALL push esi push edi mov esi, else mov esi, endif if SETZERO mov ecx, '0000' add esi, 10 mov edx, eax else mov edx, eax add esi, 10 endif if SETZERO mov dword ptr , ecx mov word ptr , cx mov dword ptr , ecx endif i = 0 rept 9 test edx, edx mov ebx, edx if $ - o upperret lt 128 jz upperret else jz getout endif dec esi ; /10 mov eax, (0FFFFFFFFH shr 1)/5+1 ;tasm doesnt do "/10", so i have to use ..shr 1) / 5.. maybe can masm do it properly, but it also works this way mul edx ; *10 lea eax, ;3 cycles add eax, edx ;- ; mod 10 sub ebx, eax db 088H, 05EH, 000H ; mov ,bl ;faster this way i = i + 1 endm test edx, edx jz raus dec esi add dl,"0" db 088H, 056H, 000H ; mov ,dl getout: mov eax, esi if REALSTDCALL pop edi pop esi endif ret 8 ENDP dw2str END
Thanks, for the proc. I'm studying it. For now I can say just that we have the same approach for most time consuming part - mod 10. I also use mul 429496730 to get reminder of div by 10 in edx. Not too long ago I find exeption for the rule. I'll see how your proc handle it. For the rest it seems different, and it is for me most interesting part. I write you back when I have some worthy to say. For now I just so one thing I don't like: mov word ptr , cx I'm sure you know what I mean, and there are numerous wayouts. For tasks there are lots of them for real worthy perposes: 62 integer convertions. Mask string and files recursive searches. Quick and line search rutines. Multy line string formation and auxilary procerudes. .ect, .ect... I think there one thing we can be sure for now - we need some place as repository for stdlib procs in Asm32, so people can submit in simple text files procs what they want to share and programmers access for their purposes. For Hutch it be good place to look and decide wich ones he would choose to include or replace in M32LIB. But also there might be procs not in M32LIB format, though interesting and usefull for Asm32 and AsmWin32 programmers. The time has come. I'm working on every day basics in asm on anvanced projects, and suppose to write fast and solve tasks. It's absolutly impossible to work proffessionaly without big wellset stdlibs. And while there were big collections for 16 bit asm(DOS oriented) in old days, nothing simular about Asm32.
I volunteer my services :0> .... I'm just setting up a page now for somewhere to keep/access a Win32asm 'StdLib' Should be done in a bit. The page will be accessible from: teddsterr.cjb.net/asm32/ email any functions to be included to: email@example.com -- with subject heading "ASM32" ... and I'll sort and group them, put them up for access/download, and also provide a zip file of the complete lib (all authors will be credited, etc) Any suggestions for what should be included in the lib (even if not yet written) will be taken That's all for now.... I think Tedd ;0)
svin, yes you might be worried about that one cx-thing. i thought it would be slower.. but it is really faster than overwriting any of the other numbers. i tried it and it was really strange.. but it is faster. (dont ask me why its faster using 16bit 66h registers in pmode but who cares ;) vineon
Finally I found time to look at your code. It have couple good lines, but the proc itself wouldn't work. I didn't start change it 'cause you are the author and it's better that you change it test it and after you get working version repost it again. If I'd correct it, it would have some from my style. So you'd better do it yourself. I only can point to obvious things: 1. "jnz raus" - there is no such label in you code "raus" 2. MASM doen't allow you aling 32. 3. stdcall preserves ebx. I hope you'll send working version soon. Better in plain mnemonics without macro, if it's possoble. Good luck with coding. The Svin.