Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int n = 10;
- int main() {
- int a[n] = {1,2,2,2,3,4,5,6,7,8}, e[n], x; //array, num elem array, x
- int c = 0;//counter for num elem array
- /*cout << "Type a[" << n << "] " << endl;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }*/
- cout << "Type element" << endl;
- cin >> x;
- int first = 0, last = n;
- if (n == 0 || a[n - 1] < x || a[0] > x) {
- cout << "No such elements in the array" << endl;
- system("pause");
- return 0;
- }
- _asm {
- mov esi,0 //esi=0 first
- mov edi,n //edi=n last
- beg_1_:
- //{
- cmp esi,edi
- jl LESS
- ///{
- jmp end_1_
- ///}
- LESS:
- ///{
- mov eax,edi //eax = last
- sub eax,esi// eax = last-first
- mov ebx,2
- cdq
- div ebx //eax =(last-first)/2
- add eax,esi//eax =(last-first)/2+first
- mov ebx,x
- cmp ebx,a[eax]
- jle LESS_EQL
- ////{
- mov esi,eax
- add esi,4
- jmp NEXT_1
- ////}
- LESS_EQL:
- ////{
- mov edi,eax
- ////}
- NEXT_1:
- jmp beg_1_
- ///}
- //}
- end_1_:
- beg_2_:
- //{
- mov eax, x
- cmp eax, a[edi]
- je EQL_2_
- ///{
- jmp end_2_
- ///}
- EQL_2_:
- ///{
- sub edi,4
- jmp beg_2_
- ///}
- //}
- end_2_:
- add edi,4
- beg_3_:
- //{
- mov eax,x
- cmp eax,a[edi]
- je EQL_
- ///{
- ///}
- jmp end_3_
- ///{
- EQL_:
- mov eax,c
- mov ebx,4
- mul ebx //c*4
- mov ecx,eax //temp
- mov eax,edi
- div ebx
- mov e[ecx],eax
- add edi,4//edi++
- mov eax,c// c++
- add eax,1
- mov c,eax
- jmp beg_3_
- ///}
- //}
- end_3_:
- }
- for (int i = 0; i<c; i++) {
- cout << e[i] << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement