Advertisement
Guest User

ASM#2

a guest
May 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void func1();
  5. void func2();
  6. void func3();
  7.  
  8. int main()
  9. {
  10.     int choice;
  11.     cout << "Choose task: ";
  12.     cin >> choice;
  13.     if (choice == 1)
  14.     {
  15.         func1();
  16.     }
  17.     else if (choice == 2)
  18.     {
  19.         func2();
  20.     }
  21.     else if (choice == 3)
  22.     {
  23.         func3();
  24.     }
  25.  
  26.     system("pause");
  27.     return 0;
  28. }
  29.  
  30.  
  31. void func1()
  32. {
  33.     short int a, b, res;
  34.     cout << "Type a: ";
  35.     cin >> a;
  36.     cout << "Type b: ";
  37.     cin >> b;
  38.     _asm {
  39.         mov ax, a
  40.         mov bx, b
  41.         cmp ax, bx
  42.         je eql_
  43.    
  44.         jl le_
  45.    
  46.         mov cx, ax
  47.         imul cx
  48.         imul cx
  49.         sub ax, 5
  50.         cdq
  51.         idiv bx
  52.         mov res, ax
  53.         jmp end_
  54.    
  55.         le_ :
  56.    
  57.         add ax, 1
  58.             mov cx, ax
  59.             mov ax, bx
  60.             cdq
  61.             idiv cx
  62.             mov res, ax
  63.             jmp end_
  64.  
  65.  
  66.             eql_ :
  67.        
  68.         mov ax, 4
  69.             mov res, ax
  70.        
  71.             end_ :
  72.     }
  73.     cout << "Result: " << res << endl;
  74. }
  75.  
  76. void func2()
  77. {
  78.     cout << "Type number: ";
  79.     int t;
  80.     cin >> t;
  81.     int quan = 0;
  82.     __asm
  83.     {
  84.         mov eax, t
  85.         mov ebx, 10
  86.         beg:
  87.         cmp eax, 0
  88.             je end_
  89.             jg gr
  90.             sub ebx, 0
  91.             jmp beg
  92.             gr :
  93.         cdq
  94.             idiv ebx
  95.             add quan, 1
  96.             jmp beg
  97.             end_ :
  98.  
  99.         mov eax, t
  100.             cmp eax, 0
  101.             jz null_
  102.             jmp endl_
  103.             null_ :
  104.         add quan, 1
  105.             endl_ :
  106.     }
  107.     cout << "Quantity of numbers: " << quan << endl;
  108. }
  109.  
  110. void func3()
  111. {
  112.     int t;
  113.     cout << "Type number: ";
  114.     cin >> t;
  115.     int quan1 = 1, modul, power = 0, res = 0;
  116.     __asm
  117.     {
  118.         mov eax, t
  119.         mov ecx, eax
  120.         mov ebx, 0
  121.         loop1:
  122.         mov eax, ecx
  123.             cmp eax, 0
  124.             jne zero1
  125.             jmp end2
  126.             zero1 :
  127.         and eax, 1
  128.             shr ecx, 1
  129.             cmp eax, 1
  130.             je equal1
  131.             jmp loop1
  132.             equal1 :
  133.         inc ebx
  134.             jmp loop1
  135.             end2 :
  136.         mov res, ebx
  137.     }
  138.     cout << "Result: " << res << endl;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement