Can anybody give me a short example on how to do floating point operations and how to display the result in EDIT control ? Thanks on help!!
Posted on 2001-01-11 15:45:00 by Milos
First of all, in order to get user's input or to display result you have to use external routines. You can write your own, but a good place to start is MASM library. You will find two routines in \MASM\M32lib called AtoFP.asm (ASCII to Floating Point) and FPtoA.asm (Floating Point to ASCII); the first one contains StrToFloat procedure to transform an ASCII string into FP format, the second one contains FloatToStr procedure to accomplish FP to ASCII conversion. Once you have your FP transformed in a string, you can easily display it on the screen. Now a little example on how to get the area of a circle when, i.e., user input it's radius. You can set up a DialogBox and get user's input with GetDlgItemText API, but before you have to setup a buffer which will contain input string: szBuffer byte 30 dup (0) ; the dimension of buffer will ;depends on which routine you will ; use to process user's input invoke GetDlgItem, hDlg, hRadius, szBuffer, 30 Ok, now szBuffer will contain our radius in ASCII format, now it's time to convert it to FP using AtoFP routine; this will return your number in a memory location (real10) you have to set: szFloat real10 ? invoke StrToFloat, addr szBuffer, addr szFloat Time to do our calculation: ;INITIALISE FPU: finit ; clear FPU stack ;LOAD RADIUS VALUE ON ST(0): fld szFloat ; ST = |Radius| ; DUPLICATE RADIUS ON ST(0) & ST(1) fld ST(0) ; ST = |Radius|Radius| ; MULTIPLY ST(1) BY ST(0) AND POP ST(0) FROM THE STACK: fmulp ST(1), ST(0) ; ST = |Radius^2| ; LOAD ON ST(0) THE VALUE OF PI fldpi ; ST = |pi|Radius^2| ;MULTIPLY ST(1) BY ST(0) AND POP ST(0) FROM THE STACK: fmulp ST(1), ST(0) ; ST = |pi*Radius^2| ; GET BACK RESULT IN MEMORY, szFloat IS OK: ; fstp szFloat ; ST = |empty| and szFloat = pi*Radius^2 Quite at the you have your result in szFloat and you must transform it in ASCII using FPtoA: invoke FloatToStr, addr szFloat, addr szBuffer Now szBuffer will contain you result as an ASCII string so you can, if you want..., display it in you DialogBox with: invoke SetDlgItemText, hDlg, hResult, addr szBuffer OK, maybe i was not too clear, but i hope this can help... Saiwa :-) P.S. Personally I don't like very much these two routines (but it's only an opinion) and I have made them by myself, so that they surely satisfy my needs...
Posted on 2001-01-11 18:24:00 by Saiwa