- 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 number of once in the given 8-bit number
In this program we will see how to count number of 1's in an 8-bit number.
Problem Statement
Write 8085 Assembly language program to count number of 1s in 8-bit number stored atlocation 8000H.
Discussion
In this program we areusing the rotate operation to count the number of 1's. As there are8 different bits in 8-bit number, then we are rotating the numbereight times. we can use RRC or RLC. Here we have used the RRCinstruction. This instruction sends the LSb to MSb also to carryflag. So after each iteration we can check the carry status to getthe count of 1s.
If the number is DA (11011010) then the answer will be 5, as there are five 1s in the number.
Input
Address | Data |
---|---|
. . . | . . . |
8000 | DA |
. . . | . . . |
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 37 | STC | Set Carry | |
F001 | 3F | CMC | ComplementCarry | |
F002 | 3A, 00, 80 | LDA 8000H | Load the number into A | |
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 by1 |
F00F | 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 reverse 8 bit number
- 8085 Program to Divide a 16-bit number by an 8-bit number
- 8085 program to convert an 8 bit number into Grey number
- 8085 program to find square of a 8 bit number
- 8085 program to find sum of digits of 8 bit number
- 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
- 8085 program to convert 8 bit BCD number into ASCII Code
- 8085 program to reverse 16 bit number
- 8085 program to show masking of lower and higher nibbles of 8-bit number
- 8085 program to check whether both the nibbles of 8 bit number are equal or not
- 8086 program to reverse 8 bit number using 8 bit operation
- 8085 program to check whether the given 16 bit number is palindrome or not
- Program to find number of bit 1 in the given number in Python
- 8086 program to divide a 16 bit number by an 8 bit number

Advertisements