Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <ctime>
- #include <vector>
- #include <string>
- #define _USE_MATH_DEFINES
- #include <math.h>
- using namespace std;
- void fill(const vector<double*> & v) {
- for (unsigned i = 0; i < v.size(); ++i) {
- *(v[i]) = (rand() % 100) / 10.0;
- }
- }
- void print(const vector<double> & v) {
- for (unsigned i = 0; i < v.size(); ++i) {
- cout << setw(10) << v[i] << endl;
- }
- }
- void print(const double * v, unsigned size) {
- for (unsigned i = 0; i < size; ++i) {
- cout << setw(10) << v[i] << endl;
- }
- }
- void print(string str, double v) {
- cout << str << setw(10) << v << endl;
- }
- double asmPow(double a, double x) {
- double y;
- __asm {
- pushad
- pushfd
- fld x;// x
- fld a;// a, x
- fyl2x;// x*log2(a)
- fld st;// x*log2(a), x*log2(a)
- frndint;// rnd(x*log2(a)), x*log2(a)
- fsub st(1), st;// rnd(x*log2(a)), frac
- fxch st(1);// frac, rnd(x*log2(a))
- f2xm1;// pow(2, frac)-1, rnd(x*log2(a))
- fld1;// 1, pow(2, frac)-1, rnd(x*log2(a))
- fadd;// pow(2, frac), rnd(x*log2(a))
- fscale;// pow(2, rnd(x*log2(a))) * pow(2, frac), rnd(x*log2(a))
- fstp st(1);// pow(2, rnd(x*log2(a))) * pow(2, frac)
- fstp y;// <empty>
- popfd
- popad
- }
- return y;
- }
- //int main() {
- // srand((unsigned)time(0));
- // double a, b, c, d, x, y1 = 0, y2 = 0, ycpp1 = 0, ycpp2 = 0;
- // fill({ &a, &b, &c, &d, &x });
- // //ycpp1 = a*pow(x, b) - b*pow(x, c) + c*x + d;
- // ycpp1 = pow(a, x);
- // y1 = asmPow(a, x);
- //
- // print({ a, b, c, d, x });
- // print("[1][C++]: ", ycpp1);
- // print("[1][ASM]: ", y1);
- // system("pause");
- // return 0;
- //}
- int main() {
- srand((unsigned)time(0));
- int k = 10; double min = 2.5; double max = 130.4;
- double a, b, p1 = 1, p2 = 1;
- double step = (max - min) / (double)k;
- double * x = new double[k];
- double * y = new double[k];
- double * xCpp = new double[k];
- double * yCpp = new double[k];
- fill({ &a, &b });
- double xi = min;
- for (int i = 0; i < k; ++i) {
- xCpp[i] = xi;
- yCpp[i] = a * sin(pow((M_PI * p1 * xi) / 180.0, 2)) + b * cos((M_PI * p2 * xi) / 180.0);
- xi += step;
- }
- double
- __asm {
- pushad
- pushfd
- fld max; // max
- fld min; // min,max
- fsub;// max-min
- fild k;// k,max-min // jak chcesz ladowac inta to musisz ladowac instrucje
- fdiv;// step = (max-min)/k
- fld max;//max,step // bedziemy odejmowac kroki ! Patrz na petle
- 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
- mov ecx, k;
- mov esi, x;//
- mov edi, y;//
- _loop:
- fst qword ptr[esi + 8 * ecx - 8];// x[i],step
- ;// a,x[i],step
- ;// calculate
- fstp qword ptr[edi + 8 * ecx - 8];// x[i],step
- fsub st(0), st(1) ;// x[i]-=step,step
- loop _loop;
- fstp st;//step
- fstp st;//<empty>
- popfd
- popad
- }
- cout << "[C++] x:" << endl;
- print(xCpp, k);
- cout << "[C++] y:" << endl;
- print(yCpp, k);
- cout << "[ASM] x:" << endl;
- print(x, k);
- cout << "[ASM] y:" << endl;
- print(y, k);
- delete[] x;
- delete[] y;
- delete[] xCpp;
- delete[] yCpp;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement