Program to count number of 1's in a given data byte


17. Program to count number of 1's in a given data byte :

mov dptr,#9000h ;Load dptr with 9000h
movx a,@dptr ;move data from external memory location to a
mov r0,#0h ;load r0 with 0
mov r1,#8h ;load r1 with 8
clr c ;clear carry bit
up:rlc a ;rotate a left through carry
jnc next ;if no carry, jump to label next
inc r0 ;increment r0
next:djnz r1,up ;decrement r1, and jump to label next, if r1?0
inc dptr ;increment dptr
mov a,r0 ;move data from r0 to a
movx @dptr,a ;move data from a to external memory location
here:sjmp here
end


Web Statistics