Advertisement
madopew

6_3

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