tfpu3.pp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. { testfdiv variant with NASM output forced }
  2. {$ifdef go32v2}
  3. {$output_format nasmcoff}
  4. {$endif}
  5. {$ifdef win32}
  6. {$output_format nasmwin32}
  7. {$endif}
  8. {$ifdef linux}
  9. {$output_format nasmelf}
  10. {$endif}
  11. { This test program deals with the
  12. the delicate problem of
  13. non commutative FPU instruction
  14. where the destination register
  15. is ST(1) to ST(7)
  16. Whereas Intel interprets
  17. fdiv st(1),st
  18. as
  19. st(1):=st(1) / st
  20. The ATT read
  21. fdiv %st,%st(1)
  22. as
  23. st(1):=st/st(1)
  24. Should be tested with
  25. different output styles :
  26. for go32v2
  27. -Aas -Acoff and -Anasmcoff
  28. for win32
  29. -Aas -Apecoff and -Anasmwin32
  30. for linux
  31. -Aas and -Anasmelf
  32. }
  33. program test_nasm_div;
  34. var
  35. x,y,z : double;
  36. begin
  37. x:=4;
  38. y:=2;
  39. Writeln('4/2=',x/y:0:2);
  40. if x/y <> 2.0 then
  41. Halt(1);
  42. {$asmmode att}
  43. asm
  44. fldl y
  45. fldl x
  46. fdivp %st,%st(1)
  47. fstpl z
  48. end;
  49. Writeln('ATT result of 4/2=',z:0:2);
  50. if z <> 2.0 then
  51. Halt(1);
  52. asm
  53. fldl y
  54. fldl x
  55. fdiv %st(1),%st
  56. fstpl z
  57. fstp %st
  58. end;
  59. Writeln('ATT result of 4/2=',z:0:2);
  60. if z <> 2.0 then
  61. Halt(1);
  62. asm
  63. fldl y
  64. fldl x
  65. fadd
  66. fstpl z
  67. end;
  68. Writeln('ATT result of 4+2=',z:0:2);
  69. if z <> 6.0 then
  70. Halt(1);
  71. {$asmmode intel}
  72. asm
  73. fld x
  74. fld y
  75. fdivp st(1),st
  76. fstp z
  77. end;
  78. Writeln('Intel result of 4/2=',z:0:2);
  79. if z <> 2.0 then
  80. Halt(1);
  81. asm
  82. fld y
  83. fld x
  84. fdiv st,st(1)
  85. fstp z
  86. fstp st
  87. end;
  88. Writeln('Intel result of 4/2=',z:0:2);
  89. if z <> 2.0 then
  90. Halt(1);
  91. asm
  92. fld y
  93. fld x
  94. fadd
  95. fstp z
  96. end;
  97. Writeln('Intel result of 4+2=',z:0:2);
  98. if z <> 6.0 then
  99. Halt(1);
  100. Writeln('All tests completed successfully!');
  101. end.