Write a 8085 program to count the number of 1’s and 0’s present in a 8-bit number
We all are familiar with the number system whether it be binary, decimal, hexadecimal, etc.
While executing programs throughout this series we have mostly taken 8-bit numbers but the 8085 microprocessor doesn’t take it as an 8-bit number rather it takes a binary number.
Therefore, whatever number we input let it be an 8-bit number or a 16-bit number, all the numbers are converted into binary format. So for this program, we are going to take an 8-bit number and then store it at any GPR.
Let the 8-bit hexadecimal number be 0AH, and instead of storing this 8-bit data on a memory location, we are going to store this value in B register.
MVI B, 0A// the 8-bit immediate data is stored at B register
MVI H, 00// the content of H register by zero
MVI L, 00 // the content of L register is set to zero
MVI C, 08 // the content of C register is assigned with 8 which will act as a counter
MOV A, B // the content of B register is copied to the accumulator
Label1 RAR //each bit of the accumulator is rotated right one by one through the carry flag
JNC Label2 // JNC will jump when carry flag is not set
INR H // the content of H register is incremented by 1
JMP Label3 // JMP will jump to DCR C
Label2 INR L // the content of L register is incremented by 1
Label3 DCR C // the content of C register gets decremented by 1
JNZ Label1 // JNZ will jump to RAR
|Memory Location||OPCODE||Operand||Label||Hex Code|