TheBulgarianWolf

C++ Assembly Exercise

Feb 13th, 2021
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int testasm(int a,int b) {
  5.     int result = 0;
  6.     __asm {
  7.         mov eax, a
  8.         add eax, b
  9.         mov result, eax
  10.     }
  11.     return result;
  12. }
  13.  
  14. //triangle perimeter
  15. int triangleP(int a, int b, int c) {
  16.     int result = 0;
  17.     __asm {
  18.         mov eax, a
  19.         add eax, b
  20.         add eax, c
  21.         mov result, eax
  22.     }
  23.     return result;
  24. }
  25.  
  26. int triangleTwoEqSides(int a, int b) {
  27.     __asm {
  28.         mov eax, a
  29.         iMul eax
  30.         add eax, b
  31.     }
  32. }
  33.  
  34. int squareP(int a) {
  35.     __asm {
  36.         mov eax, a
  37.         mov ebx, 4
  38.         mul ebx
  39.     }
  40. }
  41.  
  42. int fourP(int a,int b){
  43.     __asm {
  44.     mov eax, a
  45.     add eax,b
  46.     mov ebx, 2
  47.     mul ebx
  48.     }
  49. }
  50.  
  51. int formula(int a, int b,int c) {
  52.     __asm {
  53.         mov eax, a
  54.         inc eax
  55.         mul b
  56.         mov ebx, a
  57.         dec ebx
  58.         sub ebx, b
  59.         mov edx, 0 //tuk se zapisva ostatuka
  60.         div ebx
  61.         mul c
  62.     }
  63. }
  64.  
  65. int main() {
  66.     cout << testasm(2, 2) << endl;
  67.  
  68.     cout << triangleP(2, 3, 4) << endl;
  69.     cout << triangleTwoEqSides(2, 3) << endl;
  70.     cout << squareP(6) << endl;
  71.     cout << fourP(5, 2) << endl;
  72.     cout << formula(4, 2, 3) << endl;
  73.     system("pause");
  74.     return 0;
  75. }
Add Comment
Please, Sign In to add comment