News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

FPU - 1st result okay - subsequent results 0.000

Started by cobold, January 08, 2009, 08:46:01 PM

Previous topic - Next topic

cobold

Hello,

I'd appreciate if someone could help me with this. I look at my code and can't find out what's wrong with it.

My program calculates a percentage with this formula:
proz = (richtige+3*4 / cntgen) * hundert
The FIRST result is correct, but on subsequent calls proz is always 0.000??
cntgen is a DWORD variable, richtige is a DWORD array, proz is REALl8 ? and hundert is REAL8 100.0

Code (extract):


REPEAT 5
...
call calculate
...
...
ENDM

calculate PROC
...
...
    .if [richtige+3*4] != 0
        fild richtige+3*4
        fidiv cntgen
        fmul hundert
        fstp proz
        invoke crt_printf,SADD("%.6lf",13,10),proz
   .endif
...
...
ret


thanks in advance

cobold

raymond

The first observation is that IF the PROC is returning a good result, it must be correct (which it appears to be for computing a percentage). Since you are not providing any other details of the remainder of the program, it could be that your richtige "array" may somehow be getting rezeroed.

Also, if richtige IS an array, I don't understand why you would address the various components of such an array by richtige+3*4

The easiest way to find your problem is to trace your program in a debugger and observe (i) the memory content, and (ii) what is being loaded onto the FPU at each iteration. Ollydbg has often been my BEST FRIEND when my algos don't produce the expected results.

BTW, declaring and using 100 as a REAL8 instead of an integer is totally useless if you expect it will give you more precision.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Damos

I agree,the instruction fidiv cntgen is the problem because it divides by zero, which is something to do with the way you are addressing the array.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction. - Albert Einstien

cobold

solved - richtige was wrongly initialized, so hundert was overwriten with 0.
thks for comments!