Advertisement
artur99

ASM Check number of binary 1s

Dec 7th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7.     int a, b, cat, rest;
  8.     a = 5;
  9.  
  10.     _asm {
  11.         mov eax, a
  12.         mov ecx, 0
  13.         _while:
  14.             cmp eax, 0
  15.             je _endwhile
  16.             mov ebx, eax
  17.             and ebx, 1
  18.             add ecx, ebx
  19.             shr eax, 1
  20.             jmp _while
  21.         _endwhile:
  22.         mov b, ecx;
  23.         /* shl eax, 2*/
  24.         /* shr eax, 2*/
  25.         /* rol eax, 2*/
  26.         /* ror eax, 2*/
  27.         /* mul cx === ax * cx */
  28.         /* div b == dxax / b = ax rest dx */
  29.     };
  30.  
  31.     cout << b;
  32.     cout << endl;
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement