News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

64bit atoqw or qwtoa in any library

Started by K_F, May 19, 2015, 09:26:38 PM

Previous topic - Next topic

K_F

Just wondering...As in masm.lib where we have atodw and dwtoa functions.. is there anything available for 64 bit integers (signed and unsigned) ?
  :biggrin:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

i don't see any listed
but - this was a favorite topic of discussion in the old forum   :biggrin:
many good routines, including some fast ones by drizz, lingo, and jj - and others

i'm sure you're aware of my ling long kai fang routines (new forum) that will handle any practical size
signed, unsigned, and signed/unsigned selectable routines

K_F

Didn't know that you spoke Chinese.. :P

No not aware of your stuff - New Forum!!  where ?
8)
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave


dedndave

this is the thread in the old forum

http://www.masmforum.com/board/index.php?topic=12363

it's been downloaded almost 400 times   :biggrin:

K_F

Thanks.. I'll have a look at your magnificent coding prowness  ;)
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

it's not as fast as a dedicated 64-bit routine, of course
but, it fairs pretty well
and, it can handle any size integer you throw at it   :biggrin:

nidud

#7
deleted

dedndave

even though the name of this thread is "qwtoa using xmm registers",
drizz shows a fast routine that does not use them in the old forum...

http://www.masmforum.com/board/index.php?topic=9857.msg72422#msg72422

it's for unsigned, but can be adapted

nidud

#9
deleted

dedndave

 i think drizz uses "multiply-to-divide" to eliminate division
the following post in that thread also has a nice entry by Jochen (jj2007)

K_F

That's funny.. I was thinking of something very similar to Jochen's method. Just hadn't worked out the finer details..
:biggrin:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

K_F

#12
Changed the plan... :biggrin:

Using the FPU... just a quick snippet.. haven't initted the FPU or done some checks... the basic idea

;------------------------------------------------------------------------------
;atoqw: Convert signed intger in Ascii format to 64 bit binary number via FPU
;
;Note: The FPU status is not saved or restored. I'll do this later
;------------------------------------------------------------------------------
atoqw Proc ptr_AQW:Dword, ptr_IQW:Dword

Local TmpInt:Dword

;--- CLEAR DESTINATION [EDI] ---
xor eax,eax ;Not sure what this means
mov edi, ptr_IQW ;64Bit number destination ptr
mov [edi], eax ;
mov [edi+4], eax ;

;--- NUMBER STRING LENGTH [ESI] --
mov esi, ptr_AQW ;Ascii string ptr
Invoke szLen, esi ;masm library function
mov ecx, eax ;
dec esi ;Zero offset

;--- LOAD FPU WITH CONSTANTS --
lea edx, TmpInt ;FPU needs Addr for Int loads
m2m TmpInt, 10 ;Stage multiplier
fild DWORD PTR [edx] ;[10]
m2m TmpInt, 1 ;Current stage
fild DWORD PTR [edx] ;[1,10]
fldz ;Running Total  [0,1,10]

Looper:
xor eax, eax ;clear debris
mov al, [esi+ecx] ;load ascii
cmp al, 0 ;just in case
jne @F ;

A2QW_End:
fistp QWORD PTR [edi] ;64 bit number
fistp DWORD PTR [edx] ;clear the barrel
fistp DWORD PTR [edx] ;
Return TRUE ;Indicate success
@@:
;--- IF NEGATIVE - CHANGE SIGN ---
cmp al,'-' ;
jne @F ;
fchs ;
jmp A2QW_End ;
@@:
;--- IF POSITIVE - NO WORRY ---
cmp al,'+'
jne @F
jmp A2QW_End
@@:
;--- CHECK NUMBER RANGE ---
cmp al, '0'
jge @F
jmp A2QW_Error
@@:
;--- ANYTHING ELSE - ERROR ---
cmp al,'9'
jle @F
jmp A2QW_Error
@@:
;--- NUMBER IN RANGE ---
sub eax, 30h ;Remove ascii
mov TmpInt,eax ;
fild DWORD PTR [edx] ;[Number,Total,1,10]
fmul st(0), st(2) ;
Faddp st(1), st(0) ;[Number + Total,1,10]
fmul st(1), st(2) ;Stage adjust [Total,Stage x 10,10]
Loop Looper
        jmp A2QW_End ;

;--- ERROR DUMP AND FLAG ---
A2QW_Error:
fistp DWORD PTR [edx] ;Clear barrel
fistp DWORD PTR [edx] ;
fistp DWORD PTR [edx] ;
ret FALSE ;
atoqw Endp
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

dedndave

that's great, if it suits your specific needs   :t
in some cases, however, you don't want to use FPU or XMM registers,
because they are holding caller values when the function is used   :P

K_F

Ja.. one would have to keep an eye on that.
Batch processing a whole lot of string numbers (reading a large data file full of integer number strings)  , would make it worth while to save/restore the FPU/XMM registers.
Added a jmp after the loop  :P

This is for a 32 bit app at the mo. If it was a 64 bit app, then one could use nidud's plan
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'