Write an 8085 program to find even or odd parity - ChromeTechny
Home » Write an 8085 program to find even or odd parity

Write an 8085 program to find even or odd parity

The 8085 microprocessor has five flags that we can access, and one of them is the Parity flag located at D2 data bus.

The Parity flag is said to be set when there are even numbers of 1’s and gets reset if there are an odd number of 1’s.

So in this program, we are basically going to load an 8-bit hexadecimal number and will check whether the parity flag is set or reset.

However, there is a twist we are going to perform an addition operation between two 8-bit hexadecimal number and then we will check out whether the parity flag is set or reset.

Input:

We are going to use three memory locations; starting from 2000H to 2003H, in the 2000H and 2001H memory locations, we are going to store the 8-bit hexadecimal numbers A0H and 12H.

In 2002H memory location, we are going to store the result and in the 2003H memory location, we are going to display EE if the parity flag is set or OO in case the parity flag is reset.

Program:

LXI H, 2000 // using LXI we are going to load HL register pair to point at the content of 2000H memory location

MOV A, M // the content of 2000H will be copied to the accumulator

INX H // the HL register pair will be incremented by 1

ADD M // add operation is performed between the content of accumulator and with the content of 2001H memory location

STA 2002H // the result of addition currently stored in the accumulator will be stored at the 2002H memory location

LXI H, 2002H //using LXI we are going to load the HL register pair again to point at the 2002H memory location

MOV A, M // using MOV we are going to copy the content of 2002H to the accumulator

ORA A //using ORA we are going perform OR operation

JPO ODD //JPO jump instruction will jump in case the parity flag is reset

INR L //now if Parity flag is set then using INR we are going to increment the L register by 1

MVI M, EE // EE will be copied to 2003H memory location

HLT

Label INR L //if parity flag is reset then the jump instruction will get executed

MVI M, 00 //OO will be copied to 2003H memory location

HLT

 

Programming Details
Memory Location OPCODE Operand Label Hex Code
2004 LXI H, 2000H 21H
2005 00H
2006 20H
2007 MOV A,M 7EH
2008 INX H 23H
2009 ADD M 86H
200A STA 2002 32H
200B 02H
200C 20H
200D LXI H,2002 21H
200E 02H
200F 20H
2010 MOV A,M 7EH
2011 ORA A B7H
2012 JPO Label E2H
2013 19H
2014 20H
2015 INR L 2CH
2016 MVI M,EEH 36H
2017 EEH
2018 HLT 76H
2019 INR L Label 2C
201A MVI M,00 36H
201B 00H
201C HLT 76H

About the author

Ayan

Add Comment

Click here to post a comment

Your email address will not be published. Required fields are marked *