org 100h ; BL = Arbitrary MOV BL, 10111001b MOV BH, 0 MOV CX, 8 L: SHR BL, 1 ADC BH, 0 LOOP L ; BH now has the number of set bits in BL ret