Friday, September 2, 2011

Statement: Write an ALP of 8085 to count the number of 1's in a byte stored in the H register and store the count in E register.

MVI B,00H
MVI C,08H
MOV A,H
L2:
RAR
JNC L1
INR B
L1:
DCR C 
JNZ L2
MOV E,B
HLT

Explanation:


         In this program we are given an 8 bit data and we have to find how many 1's are there in the data ok?  To find the number of 1's we are going to take two counter.
         So, first of all we have initialized counter 1 (register B) with 00H and counter 2 (register C) with 08 H (as H register will be having 8 bit data.)
Then we have copied the data of register H to accumulator A. 


'L2' Loop:


        In this loop the data stored in accumulator is rotated alongwith carry. After the rotation if there isn't any carry then it will jump to loop L1.  Otherwise counter 1 (register B) is incremented by 1.


'L1' Loop:


       This loop will come into picture when there is no carry. At that time counter 2 (register C) is decremented by 1. If C is not equal to 00H then it'll jump to L2 loop.
        If C is equal to 00H then the data of register B is copied into the register E, which is the number of 1's in the given data.


HLT stands for 'stop'.

No comments:

Post a Comment