Question 6.15: Write a program that finds the number of 1s in a given byte.

Write a program that finds the number of 1s in a given byte.

The blue check mark means that this solution has been answered and checked by an expert. This guarantees that the final answer is accurate.
Learn more on how we answer questions.

MOV   R1,#0             ;R1 keeps number of 1s
MOV   R7,#8        ;counter, rotate 8 times
MOV   A,#97H    ;find number of 1s in 97H

AGAIN:         RLC    A                     ;rotate it thru CY

JNC    NEXT              ;check CY
INC     R1                   ;if CY=1, inc count

NEXT:           DJNZ R7,AGAIN       ;go thru 8 times

Related Answered Questions

Question: 6.8

Verified Answer:

1.     0011 0100        34H given in binary 2.    ...
Question: 6.10

Verified Answer:

MOV    P2,#00        ;clear P2 MOV    P1,#0FFH   ;...
Question: 6.13

Verified Answer:

MOV    R5,#8 AGAIN:         MOV   C,P2.7         ;...