# 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 –

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 –

1. MVI B 75 moves 75 decimal number into B register
2. MVI C 08 moves 08 decimal number into C register, which is taken as counter as the number is of 8 bites
3. MVI D 00 moves 00 number into d register
4. MOV A, B moves the contents of B register into A (accumulator) register
5. RRC rotates the contents of A (which is 75 with binary equivalent 01110101) right

6. JNC 200C jumps to 200C address and perform the instructions written there if the carry flag is not zero
7. INR D increases the value of D register by adding one to its contents
8. DCR C decreases the value of C register by subtracting one from its contents
9. JNZ 2007 jumps to 2007 address and perform the instructions written there if the zero flag is not zero
10. MOV A, D moves the contents of B register into A register
11. STA 3050 store the contents of A at 3050 memory location
12. HLT stops execution

My Personal Notes arrow_drop_up

I like to do coding in C++C and java programming languages HTML and CSS always intersts me Sharing knowleged is the best way according to me to increase ones knwoledge

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.