News:

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

x87 FSUB

Started by m7xtuf, July 21, 2010, 09:53:49 PM

Previous topic - Next topic

m7xtuf

Hello there,

   I am reading about the command FSUB for x87 floating point ... some articles said it is doing ST(0) - ST(1) while other said ST(1) - ST(0).  I write a quick program in MASM and it is showing ST(1) - ST(0) ... but how come there is that DIFFERENCE in different references ...

   HELP !!!

BogdanOntanu

Quote from: m7xtuf on July 21, 2010, 09:53:49 PM
Hello there,

   I am reading about the command FSUB for x87 floating point ... some articles said it is doing ST(0) - ST(1) while other said ST(1) - ST(0).  I write a quick program in MASM and it is showing ST(1) - ST(0) ... but how come there is that DIFFERENCE in different references ...

   HELP !!!

The definitive authority is the Intel CPU Manuals (actually 2A).

It shows that the FSUB instruction with FPU register arguments  has 2 (two) possible versions. One version that does FSUB ST0,ST(i) encoded as D8 E0+i and another version that does FSUB ST(i), ST0 encoded as DC, E8+i.

Hence it is possible that diferent people and/or articles refered to one or the other of the two possible encoding forms and arguments order.


To add a little confusion the the matter most assemblers define a "default" or simple version of FSUB with no parameters that does automatically ST0 and ST1 but choose one of the above possible encodings and forms under the hood for you.

It is beter to write the explicit form of FSUB ST0,ST1 (or the other way arround as needed by your program / algorithm) and avoid any ambiguity if possible in your assembler.
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

clive

You'd have to ask the authors, and you didn't cite any specific books, articles, etc. They could be wrong, or assume specific assemblers or opcodes.

MASM 6.15 encodes FSUB with no parameters as FSUBP st(1),st

From MASM .LST

0000002C  DC E9              fsub    st(1),st
0000002E  D8 E1              fsub    st,st(1)
00000030  DE E9              fsub

From Disassembly

0000002C DCE9                   fsub    st(1),st
0000002E D8E1                   fsub    st,st(1)
00000030 DEE9                   fsubp   st(1),st

It could be a random act of randomness. Those happen a lot as well.

Rockoon

Remember also that GAS/AT&T syntax would have them reversed from the "official" specification as well
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.