Hi Guys,

I am having some trouble understanding the basic operation of the FPU Floating Point Reg. Stack.

Please take a look at the ffg. short program:
-----------------------------------------------------------
Program MyProg;
#include("stdlib.hhf")

static
m_dFromStack: real32;

begin MyProg;
fld(3.445);
fld(23.84);

fst(m_dFromStack);
stdout.put(nl, "2nd value pushed: ", m_dFromStack); // m_dFromStack contains 23.84 after 1st pop.
fst(m_dFromStack);
stdout.put(nl, "1st value pushed: ", m_dFromStack); // m_dFromStack contains 23.84 after 2nd pop as well.
end MyProg;

-----------------------------------------------------------

I was expecting the first statement to return 23.84 and the second statement to return 3.445.

What am I not getting?


Thanks for your help.
Posted on 2004-03-01 01:17:09 by Jaysen
fst only stores the value of the top register without "popping" it. Use fstp to store and pop in a single operation.

If you want to only store the value without popping immediately (for whatever reason), you could later pop the top register with the following:

fstp st(0)

Randall's AoA has a good section on the FPU. If you are interested, the following is written in a different style and may help in further understanding the FPU's intricacies.

http://www.masmforum.com/website/tutorials/fptute/index.html

Raymond
Posted on 2004-03-01 23:28:08 by Raymond
My warmest & most grateful thanks, Raymond,

Last night after playing around a bit more with and and carrying on with the AoA manual, I managed to get how it works.

Mr Randall Hyde, I'm still using the beta version of your excellent book so I don't know if you've already updated your explanation of and in AoA. But in beta, it doesn't state that only stores but doesn't pop.

I had to read on until the and where I read about the "pop" and the "non-pop" difference (only that was for integers) before I got how and works.

My warmest and most grateful thanks.
Posted on 2004-03-02 00:45:41 by Jaysen