2
0

tfpu5.pp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. { %CPU=i386 }
  2. { %OPT=-Cg- }
  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. fdiv %st,%st(1)
  58. fstp %st
  59. fstpl z
  60. end;
  61. Writeln('ATT result of 4/2=',z:0:2);
  62. if z <> 2.0 then
  63. Halt(1);
  64. asm
  65. fldl y
  66. fldl x
  67. fadd
  68. fstpl z
  69. end;
  70. Writeln('ATT result of 4+2=',z:0:2);
  71. if z <> 6.0 then
  72. Halt(1);
  73. {$asmmode intel}
  74. asm
  75. fld x
  76. fld y
  77. fdivp st(1),st
  78. fstp z
  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. fdiv st,st(1)
  87. fstp z
  88. fstp st
  89. end;
  90. Writeln('Intel result of 4/2=',z:0:2);
  91. if z <> 2.0 then
  92. Halt(1);
  93. asm
  94. fld y
  95. fld x
  96. fadd
  97. fstp z
  98. end;
  99. Writeln('Intel result of 4+2=',z:0:2);
  100. if z <> 6.0 then
  101. Halt(1);
  102. Writeln('All tests completed successfully!');
  103. end.