Problem – Write a program to count number of ones in the given 8-bit number use register B to display the count of ones where starting address is 2000 and the number is stored at 3000 memory address and store result into 3001 memory address.
Example –

Algorithm –
- Move 00 to register B immediately for count
- Move 08 to register C immediately for shifting
- Load the data of memory [3000] into accumulator
- Rotate ‘A’ right with carry
- Jump if no carry to step-7
- Otherwise increase register B by 1
- Decrease register C by 1
- Jump if not zero to step-4
- Move content of register B into accumulator
- Store content of accumulator into memory [3001] (number of count)
- Stop
Program –
| Memory | Mnemonics | Operands | Comment |
|---|---|---|---|
| 2000 | MVI | B, 00 | [B] <- 00 |
| 2002 | MVI | C, 08 | [C] <- 08 |
| 2004 | LDA | [3000] | [A] <- [3000] |
| 2007 | RAR | rotate ‘A’ right with carry | |
| 2008 | JNC | 200C | jump if no carry |
| 200B | INR | B | [B] <- [B] + 1 |
| 200C | DCR | C | [C] <- [C] – 1 |
| 200D | JNZ | 2007 | jump if not zero |
| 2010 | MOV | A, B | [A] <- [B] |
| 2011 | STA | [3001] | number of ones |
| 2014 | HLT | Stop |
Explanation – Registers A, B and C are used for general purpose.
- MVI is used to load an 8-bit given register immediately (2 Byte instruction)
- LDA is used to load accumulator direct using 16-bit address (3 Byte instruction)
- MOV is used to transfer the data from accumulator to register(any) or register(any) to accumulator (1 Byte)
- RAR is used to shift ‘A’ right with carry (1 Byte instruction)
- STA is used to store data from accumulator into memory direct using 16-bit address (3 Byte instruction)
- INR is used to increase given register by 1 (1 Byte instruction)
- JNC is used to jump to the given step if their is no carry (3 Byte instruction)
- JNZ is used to jump to the given step if their is not zero (3 Byte instruction)
- DCR is used to decrease given register by 1 (1 Byte instruction)
- HLT is used to halt the program
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- 8085 program to count number of elements which are less than 0A
- 8085 program to count the number of ones in contents of register B
- 8085 program to convert an 8 bit number into Grey number
- 8085 program to convert an 8 bit BCD number into hexadecimal number
- 8085 program to check whether the given number is even or odd
- 8085 program to reverse 8 bit number
- 8085 program to reverse 16 bit number
- 8085 program to find nth power of a number
- 8085 program to find 1’s and 2’s complement of 16-bit number
- 8085 program to find square of a 8 bit number
- 8085 program to convert a BCD number to binary
- 8085 program to determine if the number is prime or not
- 8085 program to find sum of digits of 8 bit number
- 8085 program to find the factorial of a number
- 8085 program to find 1's and 2's complement of 8-bit number
- 8085 program to check whether the given 16 bit number is palindrome or not
- 8085 program to check whether both the nibbles of 8 bit number are equal or not
- 8085 program to search a number in an array of n numbers
- 8085 program to find minimum value of digit in the 8 bit number
- 8085 program to perform AND operation in nibbles of 8 bit number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Priti Halder

