Advertisement
Guest User

Untitled

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