Write a program to count the number of 1’s & 0’s in a number
ORH 0000H
CLR
PSW 3
CLR PSW 4
MOV R0, #00H
MOV R, #00H
MOV DTPR, #3000H
MOV A, @DPTR
L1: RLC A
JNZ L2
INC R0
L2: DJNZ R0, L1
MOV A,
#08H
CLR C
MOV R,
A
AGAIN : SJMP AGAIN
RESULT:-
INPUT OUTPUT
11010010-D2H 4-(1’S)
4-(0’S)
your program does not run in mcu. It shows a lot of errors.
ReplyDeleteNOT GOOD
mov r1,#08h
Deletemov r0,#00h
mov dptr,#8100h
movx a,@dptr
l2:rlc a
jnc l1
inc r0
l1:djnz r1,l2
inc dptr
mov a,r0
movx @dptr,a
again: sjmp again
input number should be in 8100h location
ReplyDeletethis program is to count 1s in a byte only
output result should be in 8101 location
please check any one
ORG 0000H
ReplyDeleteMOV R6,#00H
MOV R7,#00H
MOV R2,#08H
MOV R0,#30H
MOV A,@R0
CLR C
BACK: RLC A
JNC ZEROCNT
INC R7
DJNZ R2,BACK
SJMP STOP
ZEROCNT: INC R6
DJNZ R2,BACK
STOP: SJMP STOP
END
How to do it for 32 bit
ReplyDeleteWrite an ALP to count number of 0's (Zeros) of the content of the register B and Store the count at the memory location 8051H.
ReplyDelete