tfpu4.pp 1.8 KB

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