Advertisement
YauhenMardan

asm_3_r

May 11th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int a, i = 0; //a - num, i - order
  7.     cout << "Type a: ";
  8.     cin >> a;
  9.     _asm {
  10.         //count order
  11.         mov eax, a
  12.         cmp eax,0 //
  13.         je end_yes_
  14.     beg_ord:
  15.         cmp eax, 0
  16.         jle end_ord
  17.         mov ebx, 10
  18.         xor edx, edx
  19.         cdq
  20.         idiv ebx
  21.         //i++
  22.         mov ebx, i
  23.         add ebx, 1
  24.         mov i, ebx
  25.         jmp beg_ord
  26.     end_ord :
  27.     }
  28.     int l, r;// left and right temp vars
  29.     _asm{
  30.         cmp ebx,1 //num = digit
  31.         je end_yes_
  32.         //divide i by 2
  33.         mov eax, i
  34.         mov ebx, 2
  35.         xor edx, edx
  36.         cdq
  37.         idiv ebx
  38.         mov ecx, eax
  39.         mov esi,a
  40.         //beg division
  41.         beg_div:
  42.         // save ecx as external loop counter
  43.         mov edi,ecx
  44.             //devide a by 10
  45.             mov eax,esi
  46.             mov ebx,10
  47.             xor edx,edx
  48.             cdq
  49.             idiv ebx
  50.             mov r,edx //fill r
  51.             mov esi,eax //fill esi
  52.             //i-2
  53.             mov eax,i
  54.             sub eax,2
  55.             mov i,eax
  56.             //10^i (current i)
  57.             mov ecx,i //set ecx as internal loop counter
  58.             mov eax,1
  59.             cmp ecx, 0
  60.             je next_step_
  61.             mov ebx,10
  62.             beg_pow:
  63.         imul ebx
  64.         loop beg_pow
  65.             //esi/10^i
  66.             next_step_ :
  67.             mov ebx,eax
  68.             mov eax,esi
  69.             xor edx, edx
  70.             cdq
  71.             idiv ebx
  72.             mov l,eax //fill l
  73.             mov esi,edx// fill esi
  74.             //compare
  75.             mov eax,r
  76.             mov ebx,l
  77.             cmp eax,ebx
  78.             jne end_no_
  79.             //set ecx as external loop counter
  80.             mov ecx,edi
  81.             loop beg_div
  82.     }
  83. end_yes_:
  84.     cout << "Number " << a << " is symmetric" << endl;
  85.     system("pause");
  86.     return 0;
  87. end_no_:
  88.     cout << "Number " << a << " is not symmetric" << endl;
  89.     system("pause");
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement