- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
8085 program to count the number of ones in contents of register B
In this program, we will see how to count the number of 1’s in an 8-bit number stored in register B.
Problem Statement
Write 8085 Assembly language program to count the number of 1s in 8-bit number stored in register B.
Discussion
In this program, we are using the rotate operation to count the number of 1’s. As there are 8 different bits in 8-bit number, then we are rotating the number eight times. we can use RRC or RLC. Here we have used the RRC instruction. This instruction sends the LSb to MSb also to carry flag. So after each iteration, we can check the carry status to get the count of 1s.
If the number is DA (1101 1010) then the answer will be 5, as there are five 1s in the number.
Input
Register | Data |
---|---|
B | DA |
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 06, DA | | MVI B, DA | Take number 1101 1010 |
F002 | 37 | | STC | Set Carry |
F003 | 3F | | CMC | Complement Carry |
F004 | 78 | | MOV A,B | Load the number into A from B |
F005 | 0E, 08 | | MVI C,08H | Initialize the counter to 08H |
F007 | 06, 00 | | MVI B,00H | Clear B register |
F009 | 0F | LOOP | RRC | Rotate right |
F00A | D2, 0E, F0 | | JNC SKIP | If CY = 0, skip the next step |
F00D | 04 | | INR B | If CY = 1, increase B |
F00E | 0D | SKIP | DCR C | Decrease C by 1 |
F01F | C2, 09, F0 | | JNZ LOOP | If Z = 0, jump to loop |
F012 | 78 | | MOV A,B | Load the count to A |
F013 | 32, 50, 80 | | STA 8050H | Store the result at 8050H |
F016 | 76 | | HLT | Terminate the program |
Output
Address | Data |
---|---|
8050 | 05 |
- Related Articles
- 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 once in the given 8-bit number
- 8085 Program to add the contents of N word locations
- Program to count number of square submatrices with all ones using Python
- Program to add the contents of N word locations in 8085 Microprocessor
- Register codes of 8085 Microprocessor
- 8085 program to count number of elements which are less than 0A
- Flags register in 8085 Microprocessor
- 8085 Program to do an operation on two numbers based on the contents of X
- 8085 program to find the factorial of a number
- Register addressing mode in 8085 Microprocessor
- Instruction register (IR) in 8085 Microprocessor
- Temporary (temp) register in 8085 Microprocessor

Advertisements