The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: m7xtuf on July 21, 2010, 09:53:49 PM

Title: x87 FSUB
Post by: 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 !!!
Title: Re: x87 FSUB
Post by: BogdanOntanu on July 21, 2010, 10:08:28 PM
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.
Title: Re: x87 FSUB
Post by: clive on July 21, 2010, 10:12:57 PM
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

Title: Re: x87 FSUB
Post by: Rockoon on July 21, 2010, 11:07:37 PM
Remember also that GAS/AT&T syntax would have them reversed from the "official" specification as well