8051 Program To Find Number of Ones and Zeroes in A Given Number
8051 Program To Find Number of Ones and Zeroes in A Given Number
8051 Program To Find Number of Ones and Zeroes in A Given Number
Laboratory Report
On
Submitted by
March 2021
EXPERIMENT NO. 10
AIM : ( 8051 Program to find Number of Ones and Zeroes in a Given Number)
To find the number of zeros and ones in a number. The Simplest way to find the number of zeros
is by rotating each bit with carry and checking whether the carry flag is set or reset.
EQUIPMENTS/SOFTWAREREQUIRED :-
ALGORITHM :-
Explanation :–
1. MAIN: MOV R0,#12 ; number to be checked whether zero or one
2. MOV R1,#08 ; number of bits to be checked
3. MOV A,R0
4. LOOP: RLC A ; left rotating it to check each bit of number
5. JC LABEL1 ; if the bit is one jumping to one's counter
6. INC R2 ; incrementing the counter for zero bit
7. SJMP LABEL2
8. LABEL1 : INC R3 ;incrementing the counter for zero bit
9. LABEL2 : DJNZ R1,LOOP ; checking the counter of bits
10. HLT – stops executing the program and halts any further execution
OBSERVATION :-
Case-1 Case-2
Data Result Data Result
0040H - 12H R2 - 06 0040H - 91H R2 - 03
R3 - 02 R3 - 05
OUTPUT :-
CONCLUSION :-
Hence the above program was executed and the results are verified which are shown in
observation table and Outputs above.
STUDENT SIGNATURES
Arya Shipra (1904424)
Tushar Ahuja (1904448)
Atharva Priyadarshi (1904449)
Hrithik Sahu (1904469)
Submitted on 23-03-2021