# 8085 Program to Check the fourth bit of a byte

In this program, we will see how to check the 4th bit of an 8-bit number.

## Problem Statement

Write 8085 Assembly language program to check whether the fourth bit of a byte is 0 or 1.When it is 0, store 00H at any specified location, and when it is 1, store FFH at the specified location.

## Discussion

We are considering the 8-bit number, and storing 00H or FFH by checking the 4th bit on the number from left.

The logic behind it is very simple. We are just performing bit-wise and operation on the given data with 08H. If the result is non-zero, then the 4th bit is 1, otherwise, it is 0.

Data
.
.
.
.
.
.
8000
AF
.
.
.
.
.
.

Data
.
.
.
.
.
.
8000
B3
.
.
.
.
.
.

## Program

HEX Codes
Labels
Mnemonics
F000
21, 00, 80

LXI H,8000H
F003
7E

MOV A, M
F004
21, 50, 80

LXI H,8050H
F007
E6, 08

ANI 08H
AND acc with 0000 1000
F009
C2,11, F0

JNZ N ONZ
When Z flag is set, save 00H
F00C
36,00

MVI M, 00H
Save FFH when Z is not set
F00E
C3,13, F0

JMP END
F011
36, FF
NONZ
MVI M, FFH
Save 00H
F013
76
END
HLT
Terminate the program

## Output

Data
.
.
.
.
.
.
8050
FF
.
.
.
.
.
.

### second output

Data
.
.
.
.
.
.
8050
00
.
.
.
.
.
.

Updated on: 27-Jun-2020

817 Views