YauhenMardan

asm_8.7_r

May 19th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 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];
  9. cout << "Type a["<<n<<"] ";
  10. for (int i = 0; i < n;i++) {
  11. cin >> a[i];
  12. }
  13. int aq[n], ae[n];
  14. int mq, me; //max quantity, max element(quantity)
  15. int q, e; // quantity, element (for output)
  16. int c=0;//counter for aq and ae
  17. _asm
  18. {
  19. //sort
  20. mov ecx,n //set external ecx
  21. sub ecx,2
  22. beg_1_1_:
  23. //{
  24. mov ebx, ecx //save external ecx
  25. mov ecx, n //set internal ecx
  26. sub ecx, 2
  27. beg_1_2_ :
  28. ///{
  29. mov eax, ecx
  30. mov edx, 4
  31. imul edx
  32. mov esi, a[eax] // esi=a[ecx*4]
  33. add eax,4
  34. mov edi, a[eax] // esi=a[(ecx+1)*4]
  35. cmp esi,edi
  36. jl LESS
  37. ////{
  38. mov eax, ecx
  39. mov edx, 4
  40. imul edx
  41. mov a[eax],edi // swap
  42. add eax,4
  43. mov a[eax],esi //
  44. ////}
  45. LESS:
  46. ///}
  47. loop beg_1_2_
  48. //}
  49. mov ecx, ebx //set external ecx from ebx
  50. loop beg_1_1_
  51.  
  52. //
  53. mov ecx,n //counter
  54. add ecx,1
  55. mov esi,0 //offset for a[]
  56. mov edi,0 //offset for aq[] and ae[]
  57. mov eax,a[esi]
  58. mov e,eax // e=a[esi]
  59. mov eax,0
  60. mov q,eax //q=0
  61. mov eax,a[esi]
  62. mov me,eax //me=a[esi]
  63. mov mq, eax //q=0
  64.  
  65. beg_2_1:
  66. //{
  67. mov ebx,e
  68. cmp ebx,a[esi]
  69. je EQL_2_1
  70. ///{
  71. mov eax,q
  72. mov aq[edi],eax //aq[edi]=q
  73. mov eax, e
  74. mov ae[edi], eax //ae[edi]=e
  75. add edi,4 //edi+=4
  76. mov eax,c //c++
  77. add eax,1
  78. mov c,eax
  79.  
  80. mov eax,mq
  81. cmp eax,q
  82. jg GR_2_1
  83. ////{
  84. mov eax,q
  85. mov mq,eax
  86. mov eax, e
  87. mov me, eax
  88. ////}
  89. ////
  90. jmp SKIP
  91. beg_2_2:
  92. jmp beg_2_1
  93. SKIP :
  94. ////
  95. GR_2_1:
  96. mov eax,1
  97. mov q,eax
  98. mov eax,a[esi]
  99. mov e,eax
  100. jmp NEXT_2_1
  101. ///}
  102. EQL_2_1:
  103. ///{
  104. mov eax,q //q++
  105. add eax,1
  106. mov q,eax
  107. ///}
  108. NEXT_2_1:
  109. //}
  110. add esi,4 //esi+=4
  111. loop beg_2_2
  112. }
  113. for (int i = 0; i < n; i++) {
  114. cout << a[i] << " ";
  115. }
  116. cout<< endl;
  117. for (int i = 0; i<c; i++)
  118. {
  119. cout << "Elem " << ae[i] << " - " << aq[i] << endl;
  120. }
  121. cout << "Max elem " << me << " - " << mq << endl;
  122. system("pause");
  123. return 0;
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment