The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: RedXVII on March 25, 2006, 01:01:34 AM

Title: Would it be a bad thing...
Post by: RedXVII on March 25, 2006, 01:01:34 AM
If i "accidently" left floats on the FPU? What would be the consequences?

If i called a function, pushed a value on the stack, and then returned; would it still be there?

Thx  :U
Title: Re: Would it be a bad thing...
Post by: raymond on March 25, 2006, 04:40:18 AM
QuoteIf i "accidently" left floats on the FPU? What would be the consequences?

Effectively NONE if you don't use the FPU for anything else.
Effectively NONE if you always reinitialize the FPU before using it.
Otherwise, you will eventually get trash results if you "accidently" leave too many FPU registers with data in them.

QuoteIf i called a function, pushed a value on the stack, and then returned; would it still be there?

(I have to assume that you mean loading one of the FPU registers with some data.)

If the called function is one which you have written yourself, the condition of the FPU registers will remain the same as you left them before returning from the function.

Whenever you call external functions which you have not written yourself, there is always a risk that the content of the FPU could get affected. For example, some of the functions under WinXP are known to use MMX instructions (even for adding 2+2) which will trash FPU registers.

Raymond
Title: Re: Would it be a bad thing...
Post by: Tedd on March 27, 2006, 09:39:07 AM
Floating point return values are normally left on st(0) for the 'return' value - so this is fine.
If only you are using the fpu (ie. one thread within your program), you can leave it in whatever state you choose. When your process exits, it will take this state with it (ie. it won't effect any others.)

[Disclaimer: all of the above is wrong if MMX is involved :bdg]