Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int a, b, c, d, res_c, res_asm = 0;
- cout << "This program calculates (2b + 5cd)/(a-1)" << endl;
- cout << "Input only 16bit numbers!" << endl;
- cout << "Input a: ";
- cin >> a;
- cout << "Input b: ";
- cin >> b;
- cout << "Input c: ";
- cin >> c;
- cout << "Input d: ";
- cin >> d;
- res_c = 2 * b + c * d * 5;
- res_c /= a - 1;
- __asm
- {
- mov eax, c
- mov ebx, d
- mul ebx
- mov ebx, 5
- imul ebx
- mov ebx, b
- shl ebx, 1
- add eax, ebx
- mov ebx, a
- sub ebx, 1
- idiv ebx
- mov res_asm, eax
- }
- printf("Result c++: %d\nResult asm: %d\n", res_c, res_asm);
- system("pause");
- return 0;
- }
- #include <iostream>
- using namespace std;
- int main()
- {
- const int ARR_SIZE = 5;
- int arr[ARR_SIZE];
- int res_c = 0;
- int res_asm = 0;
- cout << "This program finds sum of negative elements in array of size 5" << endl;
- for (int i = 0; i < ARR_SIZE; i++)
- {
- printf("Input element %d: ", i + 1);
- cin >> arr[i];
- }
- for (int i = 0; i < ARR_SIZE; i++)
- {
- if (arr[i] < 0)
- res_c += arr[i];
- }
- __asm
- {
- lea esi, arr
- mov ecx, ARR_SIZE
- xor eax, eax
- next_:
- mov ebx, [esi]
- cmp ebx, 0
- jge skip_
- add eax, ebx
- skip_:
- add esi, 4
- loop next_
- mov res_asm, eax
- }
- printf("Result in c++: %d\nResult in asm: %d\n", res_c, res_asm);
- system("pause");
- }
- #include <iostream>
- using namespace std;
- int main()
- {
- cout << "This program finds amount of elements that are less than a number" << endl;
- cout << "Input array's size: ";
- int arr_size;
- cin >> arr_size;
- int* arr = (int*)malloc(arr_size * sizeof(int));
- for (int i = 0; i < arr_size; i++)
- {
- printf("Input element %d: ", i + 1);
- cin >> arr[i];
- }
- cout << "Input number: ";
- int number_check;
- cin >> number_check;
- int res_c = 0;
- int res_asm = 0;
- for (int i = 0; i < arr_size; i++)
- {
- if (arr[i] < number_check)
- res_c++;
- }
- __asm
- {
- mov esi, arr
- mov ecx, arr_size
- mov edx, number_check
- xor eax, eax
- next_:
- mov ebx, [esi]
- cmp ebx, edx
- jge skip_
- add eax, 1
- skip_:
- add esi, 4
- loop next_
- mov res_asm, eax
- }
- printf("Result in c++: %d\nResult in asm: %d\n", res_c, res_asm);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement