Advertisement
YauhenMardan

asm_8.1_b

May 20th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 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 //esi=0 first
  25. mov edi,n //edi=n last
  26. beg_1_:
  27. //{
  28. cmp esi,edi
  29. jl LESS
  30. ///{
  31. jmp end_1_
  32. ///}
  33. LESS:
  34. ///{
  35. mov eax,edi //eax = last
  36. sub eax,esi// eax = last-first
  37. mov ebx,2
  38. cdq
  39. div ebx //eax =(last-first)/2
  40. add eax,esi//eax =(last-first)/2+first
  41.  
  42. mov ebx,x
  43. cmp ebx,a[eax]
  44. jle LESS_EQL
  45. ////{
  46. mov esi,eax
  47. add esi,4
  48. jmp NEXT_1
  49. ////}
  50. LESS_EQL:
  51. ////{
  52. mov edi,eax
  53. ////}
  54. NEXT_1:
  55. jmp beg_1_
  56. ///}
  57. //}
  58. end_1_:
  59.  
  60. beg_2_:
  61. //{
  62. mov eax, x
  63. cmp eax, a[edi]
  64. je EQL_2_
  65. ///{
  66. jmp end_2_
  67. ///}
  68. EQL_2_:
  69. ///{
  70. sub edi,4
  71. jmp beg_2_
  72. ///}
  73. //}
  74. end_2_:
  75. add edi,4
  76. beg_3_:
  77. //{
  78. mov eax,x
  79. cmp eax,a[edi]
  80. je EQL_
  81. ///{
  82. ///}
  83. jmp end_3_
  84. ///{
  85. EQL_:
  86. mov eax,c
  87. mov ebx,4
  88. mul ebx //c*4
  89. mov ecx,eax //temp
  90. mov eax,edi
  91. div ebx
  92. mov e[ecx],eax
  93. add edi,4//edi++
  94. mov eax,c// c++
  95. add eax,1
  96. mov c,eax
  97. jmp beg_3_
  98. ///}
  99. //}
  100. end_3_:
  101. }
  102. for (int i = 0; i<c; i++) {
  103. cout << e[i] << endl;
  104. }
  105. system("pause");
  106. return 0;
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement