YauhenMardan

asm_8.1_a

May 20th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int n = 10;
  6.  
  7. int main() {
  8. int a[n] = { 1,2,2,2,3,4,5,6,7,8 }, e[n], x; //array, num elem array, x
  9. int c = 0;//counter for num elem array
  10. /*cout << "Type a[" << n << "] " << endl;
  11. for (int i = 0; i < n; i++) {
  12. cin >> a[i];
  13. }*/
  14. cout << "Type element" << endl;
  15. cin >> x;
  16. int first = 0, last = n;
  17. if (n == 0 || a[n - 1] < x || a[0] > x) {
  18. cout << "No such elements in the array" << endl;
  19. system("pause");
  20. return 0;
  21. }
  22.  
  23. _asm {
  24. mov esi, 0
  25. mov edi, n
  26.  
  27. BEG_1_ :
  28. //{
  29. cmp esi, edi
  30. jl LESS_1_
  31. ///{
  32. jmp END_1_
  33. ///}
  34. LESS_1_ :
  35. ///{
  36. xor eax,eax
  37. mov eax, edi //eax=last
  38. sub eax, esi //eax=last-first
  39. mov ebx, 2
  40. cdq
  41. idiv ebx //eax=(last-first)/2
  42. add eax, esi//eax=(last-first)/2+first
  43. mov ecx, eax//save mid
  44. mov ebx, 4
  45. imul ebx //eax=eax*4
  46. mov ebx, x
  47. cmp ebx, a[eax]
  48. jle LESS_EQL_1_
  49. ////{
  50. add esi, ecx
  51. add esi, 1
  52. jmp NEXT_1_
  53. ////}
  54. LESS_EQL_1_ :
  55. ////{
  56. mov edi, ecx
  57. ////}
  58. NEXT_1_ :
  59. ///}
  60. //}
  61. END_1_:
  62. mov x, edi
  63. }
  64. cout << x << endl;
  65. /*for (int i = 0; i<c; i++) {
  66. cout << e[i] << endl;
  67. }*/
  68. system("pause");
  69. return 0;
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment