tfpu4.pp 1.6 KB

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