Advertisement
Vanya_Shestakov

Untitled

Apr 26th, 2021
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.68 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int a, b, c, d, res_c, res_asm = 0;
  7.     cout << "This program calculates (2b + 5cd)/(a-1)" << endl;
  8.     cout << "Input only 16bit numbers!" << endl;
  9.  
  10.     cout << "Input a: ";
  11.     cin >> a;
  12.     cout << "Input b: ";
  13.     cin >> b;
  14.     cout << "Input c: ";
  15.     cin >> c;
  16.     cout << "Input d: ";
  17.     cin >> d;
  18.  
  19.     res_c = 2 * b + c * d * 5;
  20.     res_c /= a - 1;
  21.  
  22.     __asm
  23.     {
  24.         mov eax, c
  25.         mov ebx, d
  26.         mul ebx
  27.         mov ebx, 5
  28.         imul ebx
  29.         mov ebx, b
  30.         shl ebx, 1
  31.         add eax, ebx
  32.         mov ebx, a
  33.         sub ebx, 1
  34.         idiv ebx
  35.         mov res_asm, eax
  36.     }
  37.  
  38.     printf("Result c++: %d\nResult asm: %d\n", res_c, res_asm);
  39.     system("pause");
  40.     return 0;
  41. }
  42.  
  43. #include <iostream>
  44. using namespace std;
  45.  
  46. int main()
  47. {
  48.     const int ARR_SIZE = 5;
  49.     int arr[ARR_SIZE];
  50.     int res_c = 0;
  51.     int res_asm = 0;
  52.  
  53.     cout << "This program finds sum of negative elements in array of size 5" << endl;
  54.     for (int i = 0; i < ARR_SIZE; i++)
  55.     {
  56.         printf("Input element %d: ", i + 1);
  57.         cin >> arr[i];
  58.     }
  59.     for (int i = 0; i < ARR_SIZE; i++)
  60.     {
  61.         if (arr[i] < 0)
  62.             res_c += arr[i];
  63.     }
  64.     __asm
  65.     {
  66.         lea esi, arr
  67.         mov ecx, ARR_SIZE
  68.         xor eax, eax
  69.         next_:
  70.         mov ebx, [esi]
  71.         cmp ebx, 0
  72.         jge skip_
  73.         add eax, ebx
  74.         skip_:
  75.         add esi, 4
  76.         loop next_
  77.         mov res_asm, eax
  78.     }
  79.     printf("Result in c++: %d\nResult in asm: %d\n", res_c, res_asm);
  80.     system("pause");
  81. }
  82.  
  83.  
  84. #include <iostream>
  85. using namespace std;
  86.  
  87. int main()
  88. {
  89.     cout << "This program finds amount of elements that are less than a number" << endl;
  90.     cout << "Input array's size: ";
  91.     int arr_size;
  92.     cin >> arr_size;
  93.     int* arr = (int*)malloc(arr_size * sizeof(int));
  94.  
  95.     for (int i = 0; i < arr_size; i++)
  96.     {
  97.         printf("Input element %d: ", i + 1);
  98.         cin >> arr[i];
  99.     }
  100.  
  101.     cout << "Input number: ";
  102.     int number_check;
  103.     cin >> number_check;
  104.     int res_c = 0;
  105.     int res_asm = 0;
  106.  
  107.     for (int i = 0; i < arr_size; i++)
  108.     {
  109.         if (arr[i] < number_check)
  110.             res_c++;
  111.     }
  112.  
  113.     __asm
  114.     {
  115.         mov esi, arr
  116.         mov ecx, arr_size
  117.         mov edx, number_check
  118.         xor eax, eax
  119.         next_:
  120.         mov ebx, [esi]
  121.         cmp ebx, edx
  122.         jge skip_
  123.         add eax, 1
  124.         skip_:
  125.         add esi, 4
  126.         loop next_
  127.         mov res_asm, eax
  128.     }
  129.  
  130.     printf("Result in c++: %d\nResult in asm: %d\n", res_c, res_asm);
  131.     system("pause");
  132.     return 0;
  133. }
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement