i can print a number to messagebox with wsprintf like this: .data template db "%ld",0 number dd 999999 .data ? buffer db 20 dup(?) invoke wsprintf,addr buffer,addr template,bil invoke MessageBox,NULL,ADDR buffer,OFFSET AppName,MB_OK and the result is ok but how can we print number like this: number dd 999.123 i want print that number in my message box, in wsprintf the template for floating point is none there were just integer,hexadecimal,string, and char i want my messagebox show 999.123 anybody help plz ?
Hi here you find some text about wsprintf: http://asmsource.8k.com/proccalls/proc-wsprintf.htm here you find a sample using numbers :) as zip: http://asmsource.8k.com/files32/mouse32.zip as text :http://asmsource.8k.com/files32/mouse.asm.txt all from John A Lyons :) cu
I would do this with some simple math yust devide your number by 1000 and save it in some Variable then substart it from the starting value and save it into another var then call wsprintf with template db "%ld.%ld",0 and let the first argument be var2 and the second var1
thanks for your helping (WHY and theNOP) but by the way does anybody have some subroutine that is more flexible to print floating point number with wsprintf like: -123.23 -1.5 26373774747747.23 32.2 so how can we now to dive the number by 1000,100,10 or 10000000 and so on ?
sorry but I didn't get that you wanted to hav floating points, because number dd 999.123 can't be a floating point (dd is multible-DWORD) but I don't know much about floats I would be intrested too
I highly recommend FloatToStr to convert a floating point value to a 0 terminated string. Example
szBuff will then hold the string "12.34" which can be printed through a varity of methods.
include \masm32\include\masm32.inc includelib \masm32\lib\masm32.lib .data R8t Real8 12.34f .data? szBuff db 50 dup (?) .code invoke FloatToStr,R8t,addr szBuff
thank's to zadkiel :-> your routine is working but i still have a problem i just know that there is a number with type Real8 what is it ? and how can we use it in fpu (Real8) i am trying like this but the result is not correct : AppName db "Learning FPU :->",0 .data R8t Real8 12.34f number dd 10.0 .data? szBuff db 50 dup (?) sumnumber Real8 ? .code fild R8t fiadd number fistp sumnumber invoke FloatToStr,sumnumber,addr szBuff invoke MessageBox,NULL,ADDR szBuff,OFFSET AppName,MB_OK My question are : 1. Why the result is 12.34f not 22.34f ? 2. if we change the type of number by Real8 there was an error in fpu operation (sorry i am still learning) 3. Where can i find tutorial about data type and fpu in win32asm frankily i am student and always use number but there are some difficulties using number in win32asm not as easy as using number in c language or java programming
Ok, sounds like a simple problem. First prior to calling any fpu commands you should probably call finit. Maybe you are anyway you just didn't post it. But thats probably not the problem. Instead the command fispt isn't doing what you think. Its actually converting the number in the fpu to an integer and storing it as such. When you then pass this to FloatToStr it ( I think ) realises that the number is not in the floating point format and so does not create a string. Therfore when you output value your just outputing the old value. Solution: Well there are two depending on what you want 1) Use the command fstp instead of fistp. This will keep the floating point format. 2) If you want the integer value then declare sumnumber as a dword and use invoke dwtoa,sumnumber,addr szBuff to proform the number conversion to a string. Be sure to check out your masmlib help file, it has info on all the extra routines such as dwtoa, FloatToStr, etc
thank's again to zadkiel for your correction with my fpu code i have corrected my code for example fiadd with fadd that connected with real number and the result is ok :-> i start feeling that fpu it's gone a be easy