News:

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

How can I empty a real10?

Started by ecube, October 03, 2009, 10:06:51 AM

Previous topic - Next topic

ecube


MichaelW

One possibility would be:
fldz
fstp r10
eschew obfuscation

ecube

.data/
mynumb REAL10 ?

hey thanks, will it work fine on that? and will it trash anything?

MichaelW

AFAIK it will work fine. For a REAL8 or REAL4 I think it would probably be faster to load zero using integer instructions, but for a REAL10 with the odd size I doubt that the integer instructions could do it much faster.
eschew obfuscation

jj2007

You don't have to do anything, this variable is zero.

.data?
MyReal10 REAL10 ?

dedndave

not supposed to assume that, Jochen
the OS has the "right" to hand you initial garbage, as it isn't documented otherwise

anyways, a float 0 is all 0's
there are a number of ways to "reset" it to 0

        .data?

MyReal10 REAL10 ?

        .code

        xor     eax,eax
        mov     MyReal10,eax
        mov     MyReal10+4,eax
        mov     MyReal10+8,ax

that method takes a few bytes of code
using the FPU as Michael suggested is quite a bit smaller
lord only knows which is faster - lol

ecube

Thanks guys, and jj2007 I know, I meant after I use the real10 over and over, I wanna make sure its cleared first.

jj2007

Quote from: dedndave on October 03, 2009, 11:35:48 AM
not supposed to assume that, Jochen
the OS has the "right" to hand you initial garbage, as it isn't documented otherwise


Dave,
It may not be documented (?), but if M$ ever decides to hand us initial garbage, I'll offer free beer to the whole forum. We can sit together, have a picknick, and watch how the World is going down the drain. Some short wave radio stations might still work independently of Windows ::)

dedndave

i know windows usually hands you zeros
not sure about DOS - i think it is garbage
better safe than sorry - it doesn't take much to initialize it

MyReal10 dt 0.0

good to see you on, Jochen - we have missed you lately - lol

ecube

dedndave's code

xor     eax,eax
mov     dword ptr [ireal10],eax
mov     dword ptr [ireal10+4],eax
mov     word ptr [ireal10+8],ax

worked well, for some reason MichaelW's didnt, atleast at first it give me a weird return, idk...

dedndave

Michael's code should work for you, E^Cube
the code assumes that the FPU has been initialized (finit) and that there is an empty FPU register available (ST0)
try it this way...

        fldz
        fstp real10 ptr ireal10

jj2007

fldz
fstp MyReal10

... should work under normal circumstances. If it fails, check with Olly what you have in ST(7). Raymond once mentioned that certain API's, notably MessageBox, trash the FPU. If ST(7) is not empty, use ffree ST(7) before the fldz.

dedndave

i found that if i used:

MyReal dt 0.0

the assembler wanted to see:

        fstp real10 ptr MyReal

if i use:

MyReal real10 0.0

the assembler will accept:

        fstp    MyReal

i might be mistaken - lol

jj2007

Quote from: dedndave on October 03, 2009, 03:43:56 PM
MyReal dt 0.0

Both ML and JWasm accept also
MyDword dd 0.0

They shouldn't, because 0.0 is obviously a real number, while dd and dt initialise integers. At least fstp rightly throws an error...

raymond

QuoteMichael's code should work for you, E^Cube
the code assumes that the FPU has been initialized

Or that the Precision Control bits of the control word have been set for 80-bit precision.

Always remember that (at least under Windows) a clean FPU is supplied at the start of a program but with the PC bits set for 64-bit floats, i.e. double precision. At that point, the only effect of an finit instruction would be to change the PC bits to extended double precision; absolutely nothing else would be modified.

If you declare a variable as a REAL10, it must mean that you intend to perform computations at that precision level, and that you would have somehow modified the control word accordingly. Under such conditions, Michael's code would work.

But why would you "wanna make sure its cleared first"?

As for initializing variables to 0 in your data section, using REAL10 0.0 instead of dt 0 results in exactly the same thing. Thereafter, the assembler only cares about the SIZE of the variable and produces code accordingly. If you use it in FPU instructions, it will use it as a float. If you use it with integer instructions, it will treat it as an integer.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com