8051 Program To Find Number of Ones and Zeroes in A Given Number

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

MICROPROCESSOR AND MICROCONTROLLER

Laboratory Report

On

8051 Program to find Number of Ones and Zeroes in a Given


Number

(Experiment No. 10_open ended experiment 2)

Submitted by

Arya Shipra (1904424)


Tushar Ahuja (1904448)
Atharva Priyadarshi (1904449)
Hrithik Sahu (1904469)

B.Tech Programme in Electronics and Telecommunication Engineering

School of Electronics Engineering


Kalinga Institute of Industrial Technology, Deemed to be University
Bhubaneswar, India

March 2021
EXPERIMENT NO. 10

Assembly level program execution of Intel 8051 using 8051


edsim51 simulation software.

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 :-

Sl. No. Name of the Item Quantity


1. 8051 edsim51 Simulation software 1
2. Laptop/Computer system 1

ALGORITHM :-

1) Initializing R0 to the numbers to be checked and R1 to the number of bits to be checked.


2) Left or Right rotating the number with carry.
3) Checking whether the carry has zero or one.
4) If the carry is one then incrementing the counter for one and if the carry is zero then
incrementing the counter for one.
5) Checking the number of bits and repeating the above steps till the goal is reached.
This program finds the number of zeros and ones in binary equivalent number.
PROGRAM :-

Address Label Mnemonics Comments


#ORG 2000H Origin of program
0000H LJMP MAIN Long Jump to any Relative Address
#ORG 40H
0040H MAIN : MOV R0,#12 R0 <- #12
0042H MOV R1,#08 R1 <- #08
0044H MOV A,R0 A <- R0
0045H LOOP : RLC A Rotate left without carry
0046H JC LABEL1 Jump If Carry is set
0048H INC R2 Increment
0049H SJMP LABEL2 Short Jump to any Relative Address
004BH LABEL1 : INC R3 Increment
004CH LABEL2 : DJNZ R1,LOOP Decrement Register and Jump if Not
zero
HLT END

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

SIGNATURE OF THE CONCERNED LAB FACULTY MEMBER

You might also like