flat assembler
Message board for the users of flat assembler.
Index
> Main > Convert string to number |
Author |
|
6a00 04 Nov 2009, 15:45
Who knows how convert string like this '-35.027' into floating point number and reverse?
|
|||
04 Nov 2009, 15:45 |
|
windwakr 04 Nov 2009, 18:19
rugxulo wrote:
He wants to take a string and turn it into a Floating point number. If you are programming for windows, I think there is a function for this. If not(or if there is no function), you would need to parse the string yourself. EDIT: There's another topic on this subject here: http://board.flatassembler.net/topic.php?t=9338 EDIT 2: http://board.flatassembler.net/topic.php?t=7717 Last edited by windwakr on 04 Nov 2009, 20:37; edited 2 times in total |
|||
04 Nov 2009, 18:19 |
|
kohlrak 04 Nov 2009, 20:11
If you ask me, windwakr, unless he understand BCD, that link has very, very little to work with.
anyway, 6a00, i ended up giving up on this a long, long time ago and most people do. The FPU is such a painful subject (you'll find it's slow and SSE is faster but still painful to use), so really most people don't use it unless they have functions already available for it like atof and ftoa. |
|||
04 Nov 2009, 20:11 |
|
6a00 05 Nov 2009, 19:44
I found that my code gives inaccurate result
Code: proc _ascii2float ;in edi pointer to data in ecx number of characters push ebx edx eax xor eax,eax push word[edi] ffree st7 ffree st6 ffree st5 fld1 fldz fldz .loop: dec ecx js .endloop mov al,byte[edi] inc edi cmp al,'.' je .loop2 xor al,30h cmp al,9 jg .loop mov [_tmp],ax fimul word[_ten] fiadd word[_tmp] jmp .loop .loop2: dec ecx js .endloop mov al,byte[edi] inc edi xor al,30h cmp al,9 jg .loop2 mov [_tmp],ax fxch st2 ;st0 = 1 fidiv word[_ten] ;there is problem ;st0 =0.1000000000000000056 fxch st2 fxch st1 fincstp ffree st7 fldz fiadd word[_tmp] fmul st,st2 fxch st1 fadd st,st1 jmp .loop2 .endloop: fstp st1 fstp st1 pop cx cmp cl,'-' jnz @f fchs @@: pop eax edx ebx ret _ten dw 10 _tmp dw 0 endp |
|||
05 Nov 2009, 19:44 |
|
farrier 05 Nov 2009, 20:12
6a00,
Raymong Filiatreault has a site: http://www.ray.masmcode.com/ with libraries and tutorials on using the FPU and BCD numbers. In the FPU library are routines to convert from decimal to FPU and FPU to decimal. Very robust but not necessarily optimized for speed. For my own use I converted--with Raymond's permission--his library to a DLL. The code is in Masm but easy to understand +/or use. hth, farrier _________________ Some Assembly Required It's a good day to code! U.S.Constitution; Bill of Rights; Amendment 1: ... the right of the people peaceably to assemble, ... The code is dark, and full of errors! |
|||
05 Nov 2009, 20:12 |
|
vid 06 Nov 2009, 11:57
I also posted (unpublished) FASNMLIB code for ascii2float (with all sorts of input and range checking) sometime ago on this board.
|
|||
06 Nov 2009, 11:57 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.