tfpu4.pp 1.6 KB

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