tfpu5.pp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. { %CPU=i386 }
  2. { This test program deals with the
  3. the delicate problem of
  4. non commutative FPU instruction
  5. where the destination register
  6. is ST(1) to ST(7)
  7. Whereas Intel interprets
  8. fdiv st(1),st
  9. as
  10. st(1):=st(1) / st
  11. The ATT read
  12. fdiv %st,%st(1)
  13. as
  14. st(1):=st/st(1)
  15. Should be tested with
  16. different output styles :
  17. for go32v2
  18. -Aas -Acoff and -Anasmcoff
  19. for win32
  20. -Aas -Apecoff and -Anasmwin32
  21. for linux
  22. -Aas and -Anasmelf
  23. }
  24. program test_nasm_div;
  25. var
  26. x,y,z : double;
  27. begin
  28. x:=4;
  29. y:=2;
  30. Writeln('4/2=',x/y:0:2);
  31. if x/y <> 2.0 then
  32. Halt(1);
  33. {$asmmode att}
  34. asm
  35. fldl y
  36. fldl x
  37. fdivp %st,%st(1)
  38. fstpl z
  39. end;
  40. Writeln('ATT result of 4/2=',z:0:2);
  41. if z <> 2.0 then
  42. Halt(1);
  43. asm
  44. fldl y
  45. fldl x
  46. fdiv %st(1),%st
  47. fstpl z
  48. fstp %st
  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,%st(1)
  57. fstp %st
  58. fstpl z
  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. fadd
  67. fstpl z
  68. end;
  69. Writeln('ATT result of 4+2=',z:0:2);
  70. if z <> 6.0 then
  71. Halt(1);
  72. {$asmmode intel}
  73. asm
  74. fld x
  75. fld y
  76. fdivp st(1),st
  77. fstp z
  78. end;
  79. Writeln('Intel result of 4/2=',z:0:2);
  80. if z <> 2.0 then
  81. Halt(1);
  82. asm
  83. fld y
  84. fld x
  85. fdiv st,st(1)
  86. fstp z
  87. fstp st
  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. fadd
  96. fstp z
  97. end;
  98. Writeln('Intel result of 4+2=',z:0:2);
  99. if z <> 6.0 then
  100. Halt(1);
  101. Writeln('All tests completed successfully!');
  102. end.