YauhenMardan

asm_8.7_b

May 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 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,1,1,2,2,3,4,5,6,6 }; //{ 1,4,2,3,2,5,3,2,1,4 };
  9. int aq[n], ae[n];
  10. int mq, me; //max quantity, max element(quantity)
  11. int q, e; // quantity, element (for output)
  12. _asm
  13. {
  14. //sort
  15. mov esi,0 //offset
  16. mov ecx, n //counter
  17. mov q,0 //current quantity
  18. mov eax,a[esi] //current
  19. mov e,eax //element
  20.  
  21. mov eax,0 //mq=0
  22. mov mq,eax
  23. mov eax,a[esi] //me=a[esi] (a[0])
  24. mov me,eax
  25. beg_:
  26. mov eax,e
  27. cmp eax,a[esi] //q == a[esi] ?
  28. je EQL
  29. //{
  30. mov eax,q //save q
  31. mov aq[esi],eax
  32. mov eax,e //eave e
  33. mov ae[esi],eax
  34. ////
  35. jmp SKIP
  36. beg_1_:
  37. jmp beg_
  38. SKIP:
  39. ////
  40. mov eax,mq
  41. cmp eax,q //mq == q ?
  42. je EQL2
  43. ///{
  44. add esi, 4 //esi+=4
  45. jmp NEXT2
  46. ///}
  47. EQL2:
  48. ///{
  49. mov eax, q //q=mq
  50. mov mq,eax
  51. mov eax,e //e=me
  52. mov me, eax
  53. add esi, 4 //esi+=4
  54. ///}
  55. NEXT2:
  56. mov q, 0 //current quantity
  57. mov eax, a[esi] //current
  58. mov e, eax //element
  59. jmp NEXT
  60. //}
  61. EQL:
  62. //{
  63. mov eax,q // q++
  64. add eax,1
  65. mov q,eax
  66. add esi,4 //esi+=4
  67. jmp NEXT
  68. //}
  69. NEXT:
  70. loop beg_1_
  71. }
  72. for (int i = 0; i < n; i++) {
  73. cout << "element " <<ae[i]<<" - "<< aq[i]<<endl;
  74. }
  75. system("pause");
  76. return 0;
  77.  
  78. }
Add Comment
Please, Sign In to add comment