Reputation: 141
Masm allows different cpu combinations before instructions but certain combinations do not correctly detect coprocessor instructions that require a wait prefix and will cause no wait prefix when a wait prefix is required. The following combinations will cause any math coprocessor instructions after them to have NO wait prefix:
example 1: .386 .8087 ;now enter math coprocessor instruction example 2: .286 .8087 ;now enter math coprocessor instruction example 3: .386 .287 ;now enter math coprocessor instruction
if a math coprocessor instruction is then used a wait prefix (that is normally created by MASM) will NOT be created. Here are the instructions that will NOT have a wait prefix when they should have one:
FRSTOR,FFREE,FDECSTP,FINCSTP,FLDENV,FLDCW FLD,FST,FSTP,FXCH,FLDZ,FLD1,FLDPI,FLDL2E,FLDL2T, FLDLG2,FLDLN2,FILD,FIST,FISTP,FBLD,FBSTP,FCOM, FCOMP,FCOMPP,FICOM,FICOMP,FXAM,FADD,FADDP, FMUL,FMULP,FSUB,FSUBP,FSUBR,FSUBRP,FDIV,FDIVP, FDIVR,FDIVRP,FABS,FCHS,FSQRT,FRNDINT,FIADD,FIMUL, FISUB,FISUBR,FIDIV,FIDIVR,FPTAN,FPATAN,F2XM1,FSCALE, FYL2X,FYL2XP1,FPREM,FPREM1,FXTRACT,FSETPM and FNOP
These instructions are not are not affected:
FCLEX,FNCLEX,FSAVE,FNSAVE,FENI,FNENI,FDISI,FNDISI, FSTENV,FNSTENV,FINIT,FNINIT,FSTSW,FNSTSW,FSTCW and FNSTCW
Is this a bug? I have found no documentation that mentions this behavior. I do not have a later version of MASM to see if this has been fixed. The version I have is masm v6.
Upvotes: 3
Views: 308
Reputation: 93107
Only the 8087 requires a WAIT
prefix before each floating point instruction (unless you manually count out the cycles to ensure that enough time has passed for the operation to have finished). Starting with the 80286 and the 80287, the main processor would wait for coprocessor operation to finish before issuing any FPU instructions on its own without having to rely on a WAIT
instruction. An explicit WAIT
prefix is only needed if you want to observe a store or exception performed by the FPU.
For this reason, assemblers generally leave out WAIT
prefixes when the CPU selected is an 80286 or later. The instructions for which a WAIT
prefix is generated are instructions that could discard or affect pending floating point exceptions. A WAIT
prefix is generated to make sure that any floating point exception is delivered before the instruction executes. Separate variants of these instructions prefixes FN
instead of F
are usually available if this is not desired.
An 8087 coprocessor cannot be used with an 80286 or later main processor, so I suppose MASM treats the .8087
directive as “coprocessor present” rather than “8087 present.” Thus, only the main processor selected distinguishes whether WAIT
prefixes are emitted.
Upvotes: 7