8051 program to count the number of 1’s & 0’s in a number

By


Write a program to count the number of 1’s & 0’s in a number


                 ORH 0000H
                 CLR  PSW 3
                CLR   PSW   4
    MOV R0, #00H
    MOV R, #00H
    MOV DTPR, #3000H
    MOV A, @DPTR
L1:           RLC A
                JNZ  L2         
                INC R0
L2:           DJNZ R0, L1
                MOV  A, #08H
                CLR C
                MOV R, A
AGAIN : SJMP AGAIN


RESULT:-
INPUT                                   OUTPUT
11010010-D2H                       4-(1’S)
                                                4-(0’S)

0 comments:

Post a Comment

If you have any questions or droughts feel free to ask here.