I am trying to convert floating point value to string.I have tried Floattostr function but I dont know how to use it.Can anyone give me example how to convert floating point value to string ? My previous code which works with tasm on win2k does not work with MASM on win2k.Here is my code for tasm

    FADDP ST(1), ST
    call FloatToBCD
    mov     edx, offset deger
    mov     ebx,offset firstpart
    xor eax,eax
        cmp  byte ptr , '0'
        jne  Setit
        inc  edx
        jmp Rem0  
FloatToBCD   PROC   uses edi

    sub esp, 10

   ; The fbstp instruction converts the top of the stack to a
   ; packed BCD form in ten bytes, with two digits per byte.  The top 
   ; byte has the sign, which we ignore.


   ; Now we need to unpack the BCD to ASCII.

    lea esi, 
    lea edi, 
    mov ecx, 9

   mov al,       ; xxxx xxxx AAAA BBBB
   dec esi
   rol ax, 12      ; BBBB xxxx xxxx AAAA
   rol ah, 4      ; xxxx BBBB xxxx AAAA
   and ax, 0f0fh      ; 0000 BBBB 0000 AAAA
   add ax, 3030h      ; 3B3A
   mov , ax
   add edi, 2
   dec ecx

    add esp, 10

This code crashed on win98 and gaved kernel error.If I push ebp and esp and pop after call FloatToBCD then it crashes on win2k but works on win98.Sorry for double post but i guess I have posted this on wrong forum. Any help will be appreciated
Posted on 2001-02-23 18:22:00 by LaptoniC
I question your statement that the highest order BYTE containing the sign in 80-bit packed BCD format can be ignored. It's only the highest four bits that can be ignored; the low order bits of this byte give the eighteenth digit D17. At least, this is what I see when I look at Fig. 14.10 in Hyde's book "Art of Assembly Language Programming". I don't think your code was working correctly under Win98 even though it didn't crash. Don't know the details of how the BCD format actually represents a float -- i.e., whether the fbstp instruction takes care of all the BCD arithmetic to give the simplest possible result. I mean, converts the number 71.0081, say, to 3731.30303831 (the decimal point must also be handled somehow, I've just inserted it). If so, then the conversion to string form is obvious. But there might be additional BCD arithmetic lurking in the background. Hyde avoids any discussion of BCD arithmetic in his text.
Posted on 2001-02-23 19:35:00 by A. Mason
Laptronic, I think you may have a fundamental misconception of what BCD format is, and therefore of what fbstp does. I'm interested in this conversion problem, too, and it seems to me that fbstp would have to be a MIGHTY POWERRFUL opcode to do what you want it to, i.e., what A. Mason suggested. So I checked at http://developer.intel.com/design/intarch/techinfo/Pentium/fpu.htm#33480 which describes the Intel number formats. BCD is mentioned there, but it ALWAYS refers to an integer, never a true float. Concerning fbstp and Mason's example, the internal representation of 71.0083 is, after all, quite complex -- the exponent is in base two, and the conversion of the mantissa bits to base ten is highly nontrivial. But you can lay any doubts to rest by simply testing. Feed your program some floats, observe their internal representation using a debugger, and then see what fbstp does. I'll bet you don't get back anything like what the comments in your code say you expect (and which would make conversion to string form simple). Besides, if the problem were this simple wouldn't Microsoft have provided an API :) that you could call?
Posted on 2001-02-23 20:35:00 by Xmas
Ok thanks for your response my code now works on both win2k and win98.Cause of crashing was, not preserving ebx in my proc I have added ebx to uses section and all is done.What I want to learn is, howto use FloattoStr function in MASM32 library.Can anyone give me example ?.Thanks
Posted on 2001-02-24 15:37:00 by LaptoniC
LaptoniC, This is a very simplistic example of using StrToFloat,FloatToStr. It assumes you have 3 edit controls. Put a float value in "edit1" and "edit2". The procedure multiplies these two numbers and shows the results in "edit3".

Calculate proc

LOCAL str1[19]:BYTE
LOCAL str2[19]:BYTE
LOCAL str3[19]:BYTE

invoke GetWindowTextLength,hEdit1
mov    ecx,eax
invoke SendMessage,hEdit1,WM_GETTEXT,ecx,addr str1
invoke StrToFloat,addr str1,addr var1

invoke GetWindowTextLength,hEdit2
mov    ecx,eax
invoke SendMessage,hEdit2,WM_GETTEXT,ecx,addr str2
invoke StrToFloat,addr str2,addr var2

fld  var1
fld  var2
fstp var3

invoke FloatToStr,var3,addr str3
invoke SendMessage,hEdit3,WM_SETTEXT,0,addr str3
return 0

Calculate endp
Posted on 2001-02-24 22:51:00 by anon
Thanks so much!
Posted on 2001-02-25 11:44:00 by LaptoniC