Before we write the program to check whether the given 8-bit data is "2 out of 5 code" or not, let us first understand what is meant by 2 out of 5 code. An 8-bit is 2 out of 5 code if and oly if its 3 MSB bits are zero and the remaining 5 bits contains two 1's. You will be able to understand clearly from the following example shown below.
let us take the 8 bit data as 18
18 = 0001 1000
1 8
so in the above example the 3 MSB bits(i.e first 3 bits) are zero & there are two 1's in remaing 5 bits. so that makes the given 8-bit 2 out of 5 code.
Program :
// If given 8 bit is 2 out of 5 code store FFH in memory location 30H//
//If no, store 00H in memory location 30H//
ORG 00H
SJMP START
RESULT EQU 30H
START : MOV A,#_H
MOV B,A
ANL A,#0E0H
JNZ EXIT
MOV A,B
MOV R0,#05H
MOV R1,#00H
UP : RRC A
JNC DOWN
INC R1
DOWN : DJNZ R0,UP
MOV A,R1
CJNE A,#02H,EXIT
MOV RESULT,#0FFH
SJMP STOP
EXIT : MOV RESULT,#00H
STOP : SJMP STOP
END
let us take the 8 bit data as 18
18 = 0001 1000
1 8
so in the above example the 3 MSB bits(i.e first 3 bits) are zero & there are two 1's in remaing 5 bits. so that makes the given 8-bit 2 out of 5 code.
Program :
// If given 8 bit is 2 out of 5 code store FFH in memory location 30H//
//If no, store 00H in memory location 30H//
ORG 00H
SJMP START
RESULT EQU 30H
START : MOV A,#_H
MOV B,A
ANL A,#0E0H
JNZ EXIT
MOV A,B
MOV R0,#05H
MOV R1,#00H
UP : RRC A
JNC DOWN
INC R1
DOWN : DJNZ R0,UP
MOV A,R1
CJNE A,#02H,EXIT
MOV RESULT,#0FFH
SJMP STOP
EXIT : MOV RESULT,#00H
STOP : SJMP STOP
END
No comments:
Post a Comment