Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. // Laboratorium 4
  8. // Wyznaczanie iloczynu skalarnego
  9.  
  10. void print(int *p, int n){
  11. for (int i = 0; i < n; i++){
  12. cout << setw(4) << p[i] << " ";
  13. }
  14. cout << endl;
  15. }
  16.  
  17. int main()
  18. {
  19. srand((unsigned)time(0));
  20. int n = 5;
  21. int *a = new int[n];
  22. int *b = new int[n];
  23. int test = 0;
  24. int w = 0;
  25.  
  26. for (int i = 0; i < n; i++){
  27. a[i] = rand() % 10;
  28. b[i] = rand() % 10;
  29. test += a[i] * b[i];
  30. }
  31. cout << "a: ";
  32. print(a, n);
  33. cout << "b: ";
  34. print(b, n);
  35.  
  36. cout << endl;
  37.  
  38. __asm {
  39. pushad
  40. pushfd
  41.  
  42. mov esi, a
  43. mov edi, b
  44. mov ebx, 0
  45. mov ecx, n
  46.  
  47. _petla:
  48. mov eax, dword ptr [esi + 4 * ecx - 4]
  49. imul eax, dword ptr [edi + 4 * ecx - 4]
  50. add ebx, eax
  51.  
  52. loop _petla
  53. mov w, ebx
  54.  
  55. popfd
  56. popad
  57. }
  58.  
  59. cout << "[C++]:" << test << endl;
  60. cout << "[ASM]:" << w << endl;
  61.  
  62. delete[] a;
  63. delete[] b;
  64.  
  65. system("pause");
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement