How to copy values between 8087 ST(0) and ST(i) registers?

44 Views Asked by At

To copy from ST(0) to ST(i), I've figured out that fst ST(i) works.

How do I copy values from ST(i) to ST(0), without affecting other ST(...) registers or the stack? I could come up with fxch ST(i) followed by fst ST(i). Is there a single-instruction version?

1

There are 1 best solutions below

0
pts On

More Google searches haven't revealed single-instruction solution, so it's only fxch + fst. The instruction fld is not relevant, it isn't able to copy between two registers without touching other registers (as part of the stack).

Thus:

  • To copy from ST(0) to ST(i), use fst ST(i).
  • To copy from ST(i) to ST(0), use fxch ST(i) followed by fst ST(i).
  • To copy from ST(i) to ST(j), use fxch ST(i) followed by fst ST(j) followed by fxch ST(i).
  • To swap ST(0) and ST(i), use fxch ST(i).
  • To swap ST(i) and ST(j) if j != 0, use fxch ST(i) followed by fxch ST(j) followed by fxch ST(i).