开发者

Basic FPU instructions/stack overview?

I'm trying to get a basic understanding of floating point operations on x86. I understand that we have a dedicated FPU wit开发者_如何学Goh a stack, but I'm not finding much relevant information on how the stack behaves in terms of different instructions.

Basically, the addressing of the fpu registers confuses me. If I refer to st(#), am I talking about a specific register? Or is it an offset from the top of the stack?

I think most of my questions can be answered by this one example:

If I have an empty FPU stack, and run:

fld x
fld y
fmul st, st(1)

Will the result be:

ST(0) = y * x
ST(1) = x

or:

ST(0) = x * y
ST(1) = y

?

Note that the difference between these is the value in ST(1).


It's an offset from the top. The loads push the existing items further into the stack, the pops make them move back closer to the top. Here's how your little program would look execute:

                   ST(0)      ST(1)
<start>            ---         ---
fld x               x          ---
fld y               y           x
fmul st(0), st(1)  y*x          x

This reference explains it all pretty well.


The intel developer manuals would be the best place for finding how a specific fpu instruction works (and how the fpu its self works). In your example, x is loaded first, putting it at st(0), when you load y, st(0) is pushed down to st(1) and y is put into st(0). When you fmul, st(0) becomes y * x, st(1) stays x. Its basically a FILO stack(with wrap around and some other special features)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜