tfpu4.pp 1.6 KB

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