Hello,

I'm currently writing a little tool that convert an inputed number into its hexa representation in IEEE simple and double precision.Here's a schematic view of the workflow:

1) Get the ASCII string (eg: -12.10)
2) Get length of decimal part if there's one (here: 2)
3) Convert string to Hex (stored as: C A)
4) NEG each value (FFFFFFF4 FFFFFFF6)
5) Push decimal part on FPU then do: Decimal part / [10^length] eg: -10 / (10^2) = -0.1
6) Push first value on FPU stack eg: -12
7) FADD decimal part eg: -12 + -0.1 = -12.1
8) Pop onto Dword or Qword (single or double precision)
9) Convert to ASCII String (single: C141999A ; double: C028333333333333)

Everything is fine till the number is bigger than 7FFFFFFFh (but inputed as a positive value, eg: 2147483648d is 800000000h, sign bit is on). So i've got problem with those big numbers ...

What must i do to push number greater than 7FFFFFFF (but, in fact, positive numbers) on FPU stack and that this number will be interpreted as a positive value ?

I just hope i'm clear...If you don't understand i can provide more explanation.

Maybe you'll find my code is ugly, but i'm just a beginner, trying to do is best :)

Thank you very much. Regards, Neitsa.

Here's a zip with a .rap project (for radasm), all sources and compiled program included.

Feel free to comment and discuss my code if you think "that's not the right way to do it". I think that's the best way for beginners like me to learn things from advanced coders !
Posted on 2004-02-12 20:18:15 by Neitsa
Try


fild qword ptr [memory location]

fild always treats the MSB as the sign bit, so this will not work if you want to load unsigned 64bit integer. In that case, you have to abs(number) and load it and then fchs. That is the only thing I can think of right now.
Posted on 2004-02-12 20:36:08 by Starless
If you are using MASM32v8, look at the source code of the FpuAtoFL function in the FPULIB folder. If you don't have MASM32, you can get this entire library of FPU functions complete with source code from the following thread. The HELP file will also inform you about what each function attempts to achieve with the input parameters.

http://www.asmcommunity.net/board/index.php?topic=9717&highlight=fpulib

The beauty of assembly is that you can achieve similar results with a zillion different coding styles. Looking at other's code is always a learning experience even if it may not always be the ultimate way.

The FpuAtoFL code is certainly more complex than what you need because it also allows the possibility of scientific notation input. However, it check the validity of each character in the input string to avoid potential errors by the user, which is one important detail missing from your code (i.e. try your code with some letters, or other characters such as more than one decimal point, as input).

Raymond
Posted on 2004-02-12 23:59:44 by Raymond
Thank you very much for your answers.

Starless: I understand now for the MSB, but what do you mean by "abs(number)" ?
I wasn't knowing about the "fchs" instruction, but it looks so simple...( I got to read the Intel manual again and again...).

Raymond: Yes I'm using MASM32, and i've already checked the FPULIB, but maybe i've misunderstood something: I'm working only with IEEE simple (32 bits) and Double precision (64 bits), and the FPUAtoFL is for 80 bits. But maybe i'll try to convert numbers into this format, that's a good challenge ! :)


The FpuAtoFL code is certainly more complex than what you need because


Yes, you're right, i just want to convert decimal number inputed as "standard notation" (eg: 12345.98765) and not scientific notation.

However, it check the validity of each character in the input string to avoid potential errors by the user, which is one important detail missing from your code


Damn !! you're absolutely right. Damn user entering wrong strings :grin: . I'll check on subclassing my edit box.

The beauty of assembly is that you can achieve similar results with a zillion different coding styles. Looking at other's code is always a learning experience even if it may not always be the ultimate way.


That's why I like it !

Thanks a lot, gentlemen.

Regards, Neitsa.
Posted on 2004-02-13 08:28:39 by Neitsa
You are using the FPU anyway to convert your number to the IEEE format. Unless you inform the FPU otherwise, it will convert it to the 80-bit format. From there, you can store it in either the 32-bit, 64-bit or 80-bit formats.

Therefore, if you use the FpuAtoFL function and leave the result on the FPU, you can always store it separately in any format you desire. This is independant of the other functions in the library which can only use the 80-bit format from memory locations.

Raymond
Posted on 2004-02-13 13:44:36 by Raymond