Saturday, April 30, 2016

8051 Program – check nth bit of a byte

; check nth bit of a byte
; data: 4000H
;result: 4001H
ORG 0H
DATA_ADDR EQU 4000H
BIT_NO EQU 6 ;0 to 7
MAIN:
MOV DPTR,#DATA_ADDR ; fill memory
MOV A, #55H
MOVX @DPTR,A
LCALL CHECK
SJMP MAIN
CHECK:
MOV DPTR, #MASK
MOV A, #BIT_NO
MOVC A,@A+DPTR
MOV R7,A
MOV DPTR,#DATA_ADDR
MOVX A,@DPTR
ANL A,R7
MOV R7, #BIT_NO
CJNE R7,#0,find
SJMP store
find: MOV R7, #BIT_NO
loop: RR A
DJNZ R7,loop
store: INC DPTR ;increment dptr
MOVX @DPTR,A ; move data from a to external memory location
return:
RET
ORG 300H
MASK:DB 01H,02H,04H,08H,10H,20H,40H,80H
END



Related topics:
8051 Program - find out of range data   |   8051 Program - ones and twos complement   |   8051 Program - check for NULL   |   8051 Program - 1ms delay   |   8051 Program - 1sec delay timer   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment