tfpu5.pp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. fadd
  57. fstpl z
  58. end;
  59. Writeln('ATT result of 4+2=',z:0:2);
  60. if z <> 6.0 then
  61. Halt(1);
  62. {$asmmode intel}
  63. asm
  64. fld x
  65. fld y
  66. fdivp st(1),st
  67. fstp z
  68. end;
  69. Writeln('Intel result of 4/2=',z:0:2);
  70. if z <> 2.0 then
  71. Halt(1);
  72. asm
  73. fld y
  74. fld x
  75. fdiv st,st(1)
  76. fstp z
  77. fstp st
  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. fadd
  86. fstp z
  87. end;
  88. Writeln('Intel result of 4+2=',z:0:2);
  89. if z <> 6.0 then
  90. Halt(1);
  91. Writeln('All tests completed successfully!');
  92. end.