tfpu5.pp 1.5 KB

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