Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. CPP:
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. extern "C" bool check(int x1, int x2, int x3, int x4);
  7.  
  8. int main()
  9. {
  10.     int x1, x2, x3, x4;
  11.    
  12.     cout << "Введите (x1, x2): ";
  13.     cin >> x1 >> x2;
  14.  
  15.     cout << "Введите (x3, x4): ";
  16.     cin >> x3 >> x4;
  17.  
  18.     cout << check(x1, x2, x3, x4) << endl;
  19.  
  20.     return 0;
  21. }
  22.  
  23. ASM:
  24. [section .text]
  25.  
  26. global check
  27.  
  28. check:
  29.     mov eax, [esp+4]  ; arg1=x1
  30.     mov ebx, [esp+8]  ; arg2=x2
  31.  
  32.     ; eax = abs(x1-x3)
  33.     sub eax, [esp+12] ; arg3=x3
  34.  
  35. abs_eax:
  36.     neg eax
  37.     js abs_eax ; goto abs_eax if SF=1 (eax < 0)
  38.  
  39.     ; ebx = abs(x2-x4)
  40.     sub ebx, [esp+16] ; arg4=x4
  41.  
  42. abs_ebx:
  43.     neg ebx
  44.     js abs_ebx ; goto abs_eax if SF=1 (ebx < 0)
  45.  
  46.     ; if(eax == 2)
  47.     cmp eax, 2
  48.     je if_x1_sub_x3_eq_2
  49.  
  50.     ; if(eax == 3)
  51.     cmp eax, 3
  52.     je if_x1_sub_x3_eq_3
  53.  
  54.     jmp not_bitten
  55.  
  56. if_x1_sub_x3_eq_2:
  57.     cmp ebx, 3
  58.     je bitten ; if(ecx == 3)
  59.     jmp not_bitten
  60.  
  61. if_x1_sub_x3_eq_3:
  62.     cmp ebx, 2
  63.     je bitten ; if(ecx == 2)
  64.     jmp not_bitten
  65.  
  66. bitten:
  67.     mov eax, 1
  68.     ret
  69.  
  70. not_bitten:
  71.     mov eax, 0
  72.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement