I have number say 123542354 that represents number of bytes, and I want to convert it to megabytes or kilobytes and store it as ASCIIZ. But my current knowledge does not allow me to do all this, since I can work only with integer registers and FPU is still a mistery for me. I hoped that API wsprintf can do this for me but it can't
Anyway, how can I
1. divide two integers, say edx:eax with NUMBER_OF_BYTES_IN_KB constant and get real float value, not reminder
2. convert that float to ascii with say 2 digits after point (eg. 5.21 MB... I heard that there is proc in MASM package that does this, so the first question is basically the main problem here)
Posted on 2004-01-06 21:22:54 by Mikky
The MASM32 package contains a library of floating point functions. To use them, you first have to list the .inc and .lib files in your includes. You also have to consult the extensive help file to learn which parameters must be used with each function you intend to use.

One of the functions is FpuDiv for dividing 2 numbers. The other function you will need to complete your request will be FpuFLtoA which will convert the division result to a null-terminated string with the number of decimals you specify.

For example, you could use the following code to convert the number of bytes in EAX to kilobytes rounded to 2 decimal places and put the string result in kilo_buffer (using MASM syntax):
invoke FpuDiv,eax,1000,0,SRC1_DIMM or SRC2_DIMM or DEST_FPU

invoke FpuFLtoA,0,2,ADDR kilo_buffer,SRC1_FPU or SRC2_DIMM
Posted on 2004-01-06 22:49:38 by Raymond