title: Assembly (x86): Number of '01' repetitions in binary code of HEX number
body: <p>I'm new to Assembly and I have a task to determine a number of <strong>01</strong> repetitions in a binary code of a 16b hex number. For example:</p>
  
  <p>Number AB34 is: 1<strong>010 101</strong>1 0<strong>01</strong>1 <strong>01</strong>00</p>
  
  <p>As 01's are bolded above, they need to be counted and stored in RESULT in the code below. The trick is to <strong>only use logical instructions</strong> such as AND, NOT, OR, XOR, moving (SHL, SHR), rotating (ROR/RCR, ROL/RCL) and logical comparing.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>name program
  
  data segment
      BR dw 0AB34H ;
      RESULT db 0
  data ends
  
  code segment
      assume CS:code, DS:data
  start:
      mov ax, data
      mov ds, ax
  
      mov ax, BR
      mov cx, 16
      mov bx, 0
  
  lwhile:
      ; something with logical instructions
  loop lwhile
  
      mov RESULT, bl
  
      mov ah, 4ch
      int 21h
  code ends
  
  end start
  </code></pre>
  
  <p>I'm assuming that inside the loop some work needs to be done, counted through some register like bx and then moved to RESULT.</p>
  
  <p>I'm open to any suggestions, thanks in advance.</p>