Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- // Laboratorium 4
- // Wyznaczanie iloczynu skalarnego
- void print(int *p, int n){
- for (int i = 0; i < n; i++){
- cout << setw(4) << p[i] << " ";
- }
- cout << endl;
- }
- int main()
- {
- srand((unsigned)time(0));
- int n = 5;
- int *a = new int[n];
- int *b = new int[n];
- int test = 0;
- int w = 0;
- for (int i = 0; i < n; i++){
- a[i] = rand() % 10;
- b[i] = rand() % 10;
- test += a[i] * b[i];
- }
- cout << "a: ";
- print(a, n);
- cout << "b: ";
- print(b, n);
- cout << endl;
- __asm {
- pushad
- pushfd
- mov esi, a
- mov edi, b
- mov ebx, 0
- mov ecx, n
- _petla:
- mov eax, dword ptr [esi + 4 * ecx - 4]
- imul eax, dword ptr [edi + 4 * ecx - 4]
- add ebx, eax
- loop _petla
- mov w, ebx
- popfd
- popad
- }
- cout << "[C++]:" << test << endl;
- cout << "[ASM]:" << w << endl;
- delete[] a;
- delete[] b;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement