Can some tell me why when i do this:

fld Three
fld Three
fld Three
fld Three
fxch st(5)
fst Data1
fxch st(5)

The output is:
Status = 0000 h

Status = 1000 h
Data1 = 0.000000e+647
eax = 1161 h

1000 is correct for the status reg after 6 stack loads, but trying to xchange the 6'th entry with the first is causeing the status to go crazy, and the data is all corrupt.

If i go to 5 pushes, and xchg st(4)'s it works, its only when i add one more on the stack it goes nutz. Why is this? I've been scouring thu my references and nothing even hints this should be happening, but it does!

BTW: Set status uses 'fstsw' to store the status reg and display it. Three and Data1 are QWORDS.

As back ground, im trying to dump all the FPU registers *IF* they are used. Im using the TOS bits in the status reg to determin the used stack length (which is working correctly), im just hitting a brick wall when i try to dump st(5) and above.

According to the exceptions, this is a Stack Fault (Underflow) and and an invalid operation. (1161). :confused:

Thanx for any help!
Posted on 2002-05-14 17:00:32 by NaN
Well that was annoying!

I wasted my day chasing down something that doesnt exist.

I thought there was some crazy instruction failure or something.. i dunno, but i was totally looking up the wrong tree.

It has nothing to do with the FPU registers, and everything to do with the FloatToStr fuction in MASM32.LIB.

I assumed it calculated the string by scrutinizing the bits of the floating point register passed. I now learn that it uses the floating point stack as well :rolleyes: !

(( PS: Hutch, you might want to put this info in the MASM32.LIB help file ;) , since it was one of the first things i looked at when i chose to use this function. ))

So this is why everything was going nutz, it needs some stack space as well. (i didnt count the push/pops on the fpu stack in the function itself, but it would be reasonable to say now that it needs at least 3 free spaces on the stack to work).

Anywho, time to find a work around now... ah im tire of this today, im going to go and watch the playoff's first ;)

Posted on 2002-05-14 19:28:24 by NaN