Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

8085 program to count the number of ones in contents of register B

  • Last Updated : 22 May, 2018

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 –

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 



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 ADDRESSMNEMONICSCOMMENTS
2000MVI B 75B ← 75
2002MVI C 08C ← 75
2004MVI D 00D ← 00
2006MOV A, BA ← B
2007RRCRotate right without carry
2008JNC 200CJump if Not Carry
200BINR DD ← D+1
200CDCR CC ← C-1
200DJNZ 2007Jump if Not Zero
2010MOV A, DA ← D
2011STA 3050A → 3050
2014HLTStops 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
Recommended Articles
Page :

Start Your Coding Journey Now!