8085 program to count the number of ones in contents of register B
Problem – Write an assembly language program to count the number of ones in contents of register B and store the result at memory location 3050.
Example –

Algorithm –
- Convert the decimal number in Accumulator to its binary equivalent
- Rotate the digits of the binary number right without carry
- Apply a loop till count is not zero to change the values of D register and count
- Copy the value of D register to accumulator and store the result
Program –
| MEMORY ADDRESS | MNEMONICS | COMMENTS |
|---|---|---|
| 2000 | MVI B 75 | B ← 75 |
| 2002 | MVI C 08 | C ← 75 |
| 2004 | MVI D 00 | D ← 00 |
| 2006 | MOV A, B | A ← B |
| 2007 | RRC | Rotate right without carry |
| 2008 | JNC 200C | Jump if Not Carry |
| 200B | INR D | D ← D+1 |
| 200C | DCR C | C ← C-1 |
| 200D | JNZ 2007 | Jump if Not Zero |
| 2010 | MOV A, D | A ← D |
| 2011 | STA 3050 | A → 3050 |
| 2014 | HLT | Stops execution |
Explanation –
- MVI B 75 moves 75 decimal number into B register
- MVI C 08 moves 08 decimal number into C register, which is taken as counter as the number is of 8 bites
- MVI D 00 moves 00 number into d register
- MOV A, B moves the contents of B register into A (accumulator) register
- RRC rotates the contents of A (which is 75 with binary equivalent 01110101) right
- JNC 200C jumps to 200C address and perform the instructions written there if the carry flag is not zero
- INR D increases the value of D register by adding one to its contents
- DCR C decreases the value of C register by subtracting one from its contents
- JNZ 2007 jumps to 2007 address and perform the instructions written there if the zero flag is not zero
- MOV A, D moves the contents of B register into A register
- STA 3050 store the contents of A at 3050 memory location
- HLT stops execution
Recommended Posts:
- 8085 program to find 2's complement of the contents of Flag Register
- 8085 program to access and exchange the content of Flag register with register B
- 8085 program to exchange content of HL register pair with DE register pair
- 8085 program to count number of elements which are less than 0A
- 8085 program to count number of ones in the given 8-bit number
- Flag register in 8085 microprocessor
- 8085 program to check whether the given number is even or odd
- 8085 program to reverse 16 bit number
- 8085 program to reverse 8 bit number
- 8085 program to convert an 8 bit BCD number into hexadecimal number
- 8085 program to convert an 8 bit number into Grey number
- 8085 program to convert a BCD number to binary
- 8085 program to find sum of digits of 8 bit number
- 8085 program to find 1’s and 2’s complement of 16-bit number
- 8085 program to determine if the number is prime or not
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.


