Home »
Embedded Systems
Check for EVEN or ODD of 8-bit Number in 8085 Microprocessor
Check EVEN/ODD of an 8-bit Number: In this tutorial, we will learn how to check whether a given 8-bit number is EVEN or ODD in 8085 Microprocessor?
By Shivakshi Dhiman Last updated : May 13, 2023
Check whether a given 8-bit number is EVEN or ODD in 8085 Microprocessor
Problem Statement
The given number is an EVEN number if its lower bit is 0 i.e. low otherwise number is ODD.
To check whether the number is odd or even, we perform AND operation with 01 by using ANI instruction. If the number is even then we will get 00 otherwise 01 in the accumulator. We use 11 to represent odd numbers and 22 to represent even numbers.
Algorithm
- Load the accumulator with the first data.
- Perform AND operation with 01 on first data using ANI Instruction.
- Check if zero flag is set then set the value of accumulator to 22 otherwise 11 to accumulator.
- Now load the result value in memory location.
Program
LDA 2050
ANI 01
JZ **
MVI A 11
JMP ***
** MVI A 22
***STA 3050
HLT
Observation
INPUT:
2050:05
3050:11
OUTPUT:
3052:02
3053:00