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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s