flat assembler
Message board for the users of flat assembler.

Index > Windows > Type conversions

Author
Thread Post new topic Reply to topic
madpsychocell



Joined: 02 Sep 2023
Posts: 3
madpsychocell 02 Sep 2023, 14:55
How to convert types:
Int64ToFloat64
Int64ToString
Float64ToInt64
Float64ToString
StringToInt64
StringToFloat64
Crying or Very sad
Post 02 Sep 2023, 14:55
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1710
Roman 02 Sep 2023, 18:06
Read many programing books !
Than you learn how do this.

1) Using functions like as sprintf
2) Or try writ code convert text number to int value in register EAX or RAX
3) search on internet examples
Post 02 Sep 2023, 18:06
View user's profile Send private message Reply with quote
madpsychocell



Joined: 02 Sep 2023
Posts: 3
madpsychocell 02 Sep 2023, 18:23
I found some conversions in internet but not all. It is faster then sprintf.
Post 02 Sep 2023, 18:23
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3959
Location: vpcmipstrm
bitRAKE 02 Sep 2023, 18:38
Some of these can be performed by a single instruction:

Int64ToFloat64
Code:
cvtsi2sd xmm0, rax  ; rax contains the int64, xmm0 will contain the float64    
Float64ToInt64
Code:
cvttsd2si rax, xmm0  ; xmm0 contains the float64, rax will contain the int64    

Some have legacy window functions (confusing naming without floating-point support):

StringToInt64 - SHLWAPI.wnsprintfA
Int64ToString - USER32.wsprintfA

All the operations can be performed by UCRT, but there is an abstraction layer.
MSVCRT doesn't have the abstraction layer - containing atof(), atol(), printf(), sprintf(), etc. functions.

There are conversion functions on this board as well. FPU
Post 02 Sep 2023, 18:38
View user's profile Send private message Visit poster's website Reply with quote
madpsychocell



Joined: 02 Sep 2023
Posts: 3
madpsychocell 02 Sep 2023, 21:04
I have to find a conversions: string to double, double to string and int to string in x64...
Post 02 Sep 2023, 21:04
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3959
Location: vpcmipstrm
bitRAKE 03 Sep 2023, 00:40
Are you looking for the cutting edge AVX512, super optimized version or something? Or are you looking to learn about the IEEE floating point format. Int to string is trivial if coded for size:
Code:
virtual CONST.32 ; "base32hex", RFC 2938, Sec.3-1
        digit_table db '0123456789ABCDEFGHIJKLMNOPQRSTUV'
end virtual

align 16, codepad #
UINT64__Baseform:
; RAX: number to convert
; RCX: number base to use [2,32] radix
; RDI: string buffer of length [65,14] bytes
        push 0 ; sentinel
.A:     xor edx,edx
        div rcx
        push qword [digit_table+rdx] ; #32#
        test rax,rax
        jnz .A

.B:     pop rax
        stosb
        test al,al
        jnz .B
        retn    
Post 03 Sep 2023, 00:40
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3959
Location: vpcmipstrm
bitRAKE 03 Sep 2023, 02:31
In windows there are many ways to convert double/float to string.

*oleaut32.VarBstrFromR8() supports the full range of the IEEE format - generating inf, nan and processing subnormals. (Not to mention the locale presentation of numbers - for those people that like to see 123,456 instead of 123.456.)

*Click the link for the dozens of conversion functions present in this library!


Description: The OLEAUT32 library convert double to string.
Download
Filename: double.ole.zip
Filesize: 1.74 KB
Downloaded: 122 Time(s)


_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 03 Sep 2023, 02:31
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1710
Roman 06 Sep 2023, 10:58
VarBstrFromR8 Unicode string.
And BSTR it is a COM object.

Wow !

I never used VarBstrFromR8.

Sound like as Bastard from reality number 8 Smile
Post 06 Sep 2023, 10:58
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3959
Location: vpcmipstrm
bitRAKE 07 Sep 2023, 09:46
The OLE stuff has it's place, but the overhead of that library is a little steep for one function. The function names can be misleading because they don't all produce VARIANT types - more like VARIANT support functions.

Here is another one - not meant to be the fastest - just get the job done:
Code:
align 16, codepad #
atoi64:
        xor     ecx, ecx
        cmp     byte [rdi], '-'
        setz    cl
        add     rdi, rcx
        bts     rcx, 63
        xor     eax, eax
        push    rdi
.read_digits:
        movzx   edx, byte [rdi]
        sub     edx, '0'
;       jc      .done
        cmp     edx, 10
        jnc     .done
        imul    rax, rax, 10
        jo      .overflow
        add     rax, rdx
        add     rdi, 1
        cmp     rax, rcx
        jc      .read_digits
.overflow:
        pop     rdi
        push    rdi
.done:
        jecxz   .positive ; note ECX!
        neg     rax
.positive:
        pop     rcx
        sub     ecx, edi
        retn
; ZF=1, RCX=0 on error
; RDI updated
; RAX signed-qword    
... it's 60 bytes. Razz

atou64() would just be a reduction of this function.


Description: [fasmg] Examine function interface/accuracy, test cases.
Download
Filename: atoi64.inc
Filesize: 2.93 KB
Downloaded: 105 Time(s)


_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 07 Sep 2023, 09:46
View user's profile Send private message Visit poster's website 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.