Hi, I need help converting from ascii to float and viceversa.

I ask for a number (it must be real) and I save it in msg1 (msg1    BYTE    80 DUP(?))

Then I have to convert it into Float number, so I use INVOKE FpuAtoFL, ADDR msg1, ADDR capital,DEST_MEM  where capital is a REAL10 variable.

Then I want convert it again into ascii and print it: INVOKE  FpuFLtoA, ADDR capital,4, ADDR msg1,STR_REG or SRC1_REAL

The problem is that can't print it correctly.

For print i use: INVOKE WriteConsole, consoleOutputHandle, ADDR msg1, bytesRead, ADDR bytesWritten, 0

I have two problems really: the first one is that can't print it. And the second is the "bytesRead". When I worked with integers I had a procedure that returned on eax the numbers of bytes read when I converted from binary to ascii. But now I don't know how to get it.

Posted on 2011-07-04 13:00:01 by ayozito
The FpuFLtoA function does not return the number of characters; however, it does return a null-terminated string. You will have to count the number of characters yourself. For example, you could do it as follows:

  lea edx,msg1
  xor ecx,ecx
  cmp byte ptr,0
  jz  done
  inc ecx
  jmp count
;ECX is the number of characters excluding the terminating "0"
Posted on 2011-07-04 22:48:25 by Raymond
tried and same... the parameters to the function are in the correct order?
Posted on 2011-07-06 11:46:05 by ayozito
Post some code plz :)
Posted on 2011-07-06 13:23:50 by JimmyClif

I would have thought that, if you are using the Fpulib, you would also have access to the help file which describes each function and related parameters in detail. Otherwise, download the latest version of the lib, which includes the help file in .chm format, from:

You invoke the FpuAtoFL function correctly. However, you are not using the parameters for the FpuFLtoA function in the correct order.

Also, make sure the function you use to get the input returns a null-terminated string (as required by the FpuAtoFL function) into msg1.
Posted on 2011-07-06 19:27:14 by Raymond
I found the problem, but don't know how to fix it. The problem is that the string isn't terminated in 0.

When I save the string into msg1 I have a variable that tell me how much bytes were read (bytesRead). So I'm trying to do the following:

mov ebx, bytesRead
mov msg1,0

but isn't working. However I created a variable for example aux BYTE "421421.2424",0 and on this way it works.

But I need convert the msg1 so now the other problem is.. how can I end the string in 0?
Posted on 2011-07-07 10:36:16 by ayozito
How do you ask for a number?

Most API's to retrieve a number/text terminate the input with zero.

How about zero'ing out your buffer before writing in the number?
Posted on 2011-07-07 11:19:14 by JimmyClif
When you tried
mov msg1,0
and mention it isn't working, what kind of result were you getting that you considered incorrect???
Posted on 2011-07-07 21:22:47 by Raymond
after conversion, eax is 0 so it was bad conversion.

Just found a procedure for convert Ascii to Float. Now I am using it and for Float to Ascii I am using the Fpu one.

Now I have other problem, but isn't related with this so I will open other topic.

Thak you for help
Posted on 2011-07-08 09:35:35 by ayozito

One last question. Are you getting your input string as standard ascii or as unicode? If the latter, the FpuAtoFL is not designed to handle unicode strings and would return the error code.
Posted on 2011-07-08 10:30:01 by Raymond
Really, don't know.

I have the variable msg1 BYTE anchobuffer DUP(?) and then for get the string I write:

    INVOKE ReadConsole,
        consoleInputHandle, ADDR msg1, anchobuffer-2,
        ADDR bytesRead, 0

ps: anchobuffer = 80
Posted on 2011-07-08 11:07:45 by ayozito