Advertisement
madopew

6_2

Apr 4th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     const int ARR_SIZE = 5;
  6.     int arr[ARR_SIZE];
  7.     int res_c = 0;
  8.     int res_asm = 0;
  9.     cout << "This program finds sum of negative elements in array of size 5" << endl;
  10.     for (int i = 0; i < ARR_SIZE; i++) {
  11.         printf("Input element %d: ", i + 1);
  12.         cin >> arr[i];
  13.     }
  14.     for (int i = 0; i < ARR_SIZE; i++) {
  15.         if (arr[i] < 0)
  16.             res_c += arr[i];
  17.     }
  18.  
  19.     __asm {
  20.         lea esi, arr
  21.         mov ecx, ARR_SIZE
  22.         xor eax, eax
  23.         next_: 
  24.             mov ebx, [esi]
  25.             cmp ebx, 0
  26.             jge skip_
  27.             add eax, ebx
  28.             skip_: 
  29.                 add esi, 4
  30.                 loop next_
  31.         mov res_asm, eax
  32.     }
  33.  
  34.     printf("Result in c++: %d\nResult in asm: %d\n", res_c, res_asm);
  35.     system("pause");
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement