Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctime>
  4. #include <vector>
  5. #include <string>
  6. #define _USE_MATH_DEFINES
  7. #include <math.h>
  8. using namespace std;
  9. void fill(const vector<double*> & v) {
  10. for (unsigned i = 0; i < v.size(); ++i) {
  11. *(v[i]) = (rand() % 100) / 10.0;
  12. }
  13. }
  14. void print(const vector<double> & v) {
  15. for (unsigned i = 0; i < v.size(); ++i) {
  16. cout << setw(10) << v[i] << endl;
  17. }
  18. }
  19. void print(const double * v, unsigned size) {
  20. for (unsigned i = 0; i < size; ++i) {
  21. cout << setw(10) << v[i] << endl;
  22. }
  23. }
  24. void print(string str, double v) {
  25. cout << str << setw(10) << v << endl;
  26. }
  27. double asmPow(double a, double x) {
  28. double y;
  29. __asm {
  30. pushad
  31. pushfd
  32.  
  33. fld x;// x
  34. fld a;// a, x
  35. fyl2x;// x*log2(a)
  36. fld st;// x*log2(a), x*log2(a)
  37. frndint;// rnd(x*log2(a)), x*log2(a)
  38. fsub st(1), st;// rnd(x*log2(a)), frac
  39. fxch st(1);// frac, rnd(x*log2(a))
  40. f2xm1;// pow(2, frac)-1, rnd(x*log2(a))
  41. fld1;// 1, pow(2, frac)-1, rnd(x*log2(a))
  42. fadd;// pow(2, frac), rnd(x*log2(a))
  43. fscale;// pow(2, rnd(x*log2(a))) * pow(2, frac), rnd(x*log2(a))
  44. fstp st(1);// pow(2, rnd(x*log2(a))) * pow(2, frac)
  45. fstp y;// <empty>
  46.  
  47. popfd
  48. popad
  49. }
  50. return y;
  51. }
  52. //int main() {
  53. // srand((unsigned)time(0));
  54. // double a, b, c, d, x, y1 = 0, y2 = 0, ycpp1 = 0, ycpp2 = 0;
  55. // fill({ &a, &b, &c, &d, &x });
  56. // //ycpp1 = a*pow(x, b) - b*pow(x, c) + c*x + d;
  57. // ycpp1 = pow(a, x);
  58. // y1 = asmPow(a, x);
  59. //
  60. // print({ a, b, c, d, x });
  61. // print("[1][C++]: ", ycpp1);
  62. // print("[1][ASM]: ", y1);
  63. // system("pause");
  64. // return 0;
  65. //}
  66.  
  67. int main() {
  68. srand((unsigned)time(0));
  69. int k = 10; double min = 2.5; double max = 130.4;
  70. double a, b, p1 = 1, p2 = 1;
  71. double step = (max - min) / (double)k;
  72. double * x = new double[k];
  73. double * y = new double[k];
  74. double * xCpp = new double[k];
  75. double * yCpp = new double[k];
  76.  
  77. fill({ &a, &b });
  78.  
  79. double xi = min;
  80.  
  81. for (int i = 0; i < k; ++i) {
  82. xCpp[i] = xi;
  83. yCpp[i] = a * sin(pow((M_PI * p1 * xi) / 180.0, 2)) + b * cos((M_PI * p2 * xi) / 180.0);
  84. xi += step;
  85. }
  86.  
  87. double
  88. __asm {
  89.  
  90.  
  91. pushad
  92. pushfd
  93.  
  94. fld max; // max
  95. fld min; // min,max
  96. fsub;// max-min
  97. fild k;// k,max-min // jak chcesz ladowac inta to musisz ladowac instrucje
  98. fdiv;// step = (max-min)/k
  99. fld max;//max,step // bedziemy odejmowac kroki ! Patrz na petle
  100. fsub st(0), st(1);// ta instrukcja jest dlatego ,zeby bylo tak jak w C++, chodzi o to ,ze dobijamy do maxa a w C++ jest warunek ,ze ma byc mniejszy
  101. mov ecx, k;
  102. mov esi, x;//
  103. mov edi, y;//
  104. _loop:
  105.  
  106. fst qword ptr[esi + 8 * ecx - 8];// x[i],step
  107.  
  108.  
  109. ;// a,x[i],step
  110.  
  111. ;// calculate
  112.  
  113. fstp qword ptr[edi + 8 * ecx - 8];// x[i],step
  114. fsub st(0), st(1) ;// x[i]-=step,step
  115.  
  116.  
  117. loop _loop;
  118.  
  119. fstp st;//step
  120. fstp st;//<empty>
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. popfd
  128. popad
  129. }
  130.  
  131. cout << "[C++] x:" << endl;
  132. print(xCpp, k);
  133. cout << "[C++] y:" << endl;
  134. print(yCpp, k);
  135. cout << "[ASM] x:" << endl;
  136. print(x, k);
  137. cout << "[ASM] y:" << endl;
  138. print(y, k);
  139.  
  140. delete[] x;
  141. delete[] y;
  142. delete[] xCpp;
  143. delete[] yCpp;
  144.  
  145. system("pause");
  146. return 0;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement