Saturday, April 30, 2016

8051 Program – count 0 and 1 in a byte

; count 0 and 1 in a byte
; input in A
; number of 1 in R1
; number of 0 in R2
ORG 0H
DATA_ADDR EQU 4000H
MAIN:
MOV R1,#0
MOV R7,#8 ;count=08
MOV A,#97H
AGAIN: RLC A
JNC NEXT ;check for CY
INC R1 ;if CY=1 add to count
NEXT: DJNZ R7,AGAIN
MOV A, #8
CLR C
SUBB A,R1
MOV R2,A
END



Related topics:
8051 Program - search an element in an array   |   8051 Program - search a byte in array and count match   |   8051 Program - square of a given number 8bit   |   8051 Program - square root of a given number 8bit   |   8051 Program - square and cube operation   |   8051 Program - count number of ones in a byte   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment