Monday, April 4, 2011

Count the number of 1's in register


; EXAMPLE H = 0101 0010 = 52 NUMBER OF 1'S =3
;
;


MVI C, 00H ; nUMBER OF 1'S
MVI B, 08H ; AS THERE ARE ONLY 8 BITS IN REGISTER
LXI H, 2000H ;
MOV A, M ;
L2 RAR ; ROTATE THROUGH CARRY
JNC L1 ; IF CARRY 1 CONTINUE
INR C ;
L1 DCR B ;
JNZ L2 ;
MOV A, C ;
STA 1FFFH ;
HLT

No comments:

Post a Comment