8085 Program to count the number of 1’s in a register

In this program, we will write an 8085 Program to count the number of 1’s in a register in the 8085 microprocessor with a program flow chart and explanation of the program.

8085 Program to count the number of 1’s in a register

Program Statement

Write a program in the assembly language programming of 8085 to count the number of 1’s in a byte stored in the H register and store the count in the E register. Draw flowchart

Explanation of Program

  • We have a byte that is stored in the H register.
  • Initialize the counter-1 = 8 i.e. total number of bits in a byte.
  • Initialize counter-2 = 0 to count the number of 1’s.
  • We will rotate the number in A along with carry by 1 bit to the right if there is a carry we will increment counter-2.
  • Decrement counter-1. This process will continue till all the bits are checked. The counter-2 will indicate the number of 1’s present in the byte.
  • The result of counter-2 is stored in B.
  • e.g. : H = 0101 0010 = 52, Number of 1’s = 3

Flow Chart of Program

8085 Program to count the number of 1’s in a register

Assembly Language Program

LabelInstructionCommentOperation
MVI B, 00HInitialize counter-1 = 00HB = 00H
MVI C, 08HInitialize counter-2 = 08HC = 08H
MOV A, HLoad the number in the accumulatorA = 52H
L2:RARRotate the number along with the carry
JNC L1if no carry goto L1
INR Bincrement the countB = B + 1
L1:DCR Cdecrement counter-2C = C -1
JNZ L2check if counter = 0? if not continue
MOV E, BStore the result in register EE = 03H
HLTterminate program executionStop
Sr. No.Name of the 8085 Programs
1.Write a program to load the data into the accumulator and any register.
2.Write a program to exchange the contents of memory locations.
3.Add two 8-bit numbers.
4.Subtract two 8-bit numbers.
5.Add two 16-bit numbers.
6.Subtract two 16-bit numbers
7.Find the 1’s complement of a Number
8.Find the 2’s complement of a Number
9.8085 Program To Mask The Lower Nibble
10.8085 Program To Mask The Upper Nibble
11.8085 program to pack the two unpacked BCD numbers
12.8085 program to Unpack the two packed BCD numbers
13.8085 program to find the sum of a series of 8-bit numbers
14.8085 Program to sort the numbers in ascending order
15.8085 Program to sort the numbers in Descending order
16.8085 Program to Multiply Two 8-bit Numbers
17.8085 Program to Divide 16-bit number by 8-bit number
18.8085 Program to Find the Number of Negative Numbers in Array
19.8085 Program to Find Maximum Number in Array
20.8085 Program to count the number of 1’s in a register

Hello friends, my name is Trupal Bhavsar, I am the Writer and Founder of this blog. I am Electronics Engineer(2014 pass out), Currently working as Junior Telecom Officer(B.S.N.L.) also I do Project Development, PCB designing and Teaching of Electronics Subjects.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

telegram logo Join Our Telegram Group!