Write an 8085 program to evaluate the expression y=a+b-c, where a, b are 16-bit hexadecimal numbers and c is a 8-bit number - ChromeTechny
Home » Write an 8085 program to evaluate the expression y=a+b-c, where a, b are 16-bit hexadecimal numbers and c is a 8-bit number
8085 Programming

Write an 8085 program to evaluate the expression y=a+b-c, where a, b are 16-bit hexadecimal numbers and c is a 8-bit number

In the last program, we saw how we can evaluate an expression which included 16-bit hexadecimal numbers, however, in the last two programs, we only did addition operation.

But in this program other than addition, we are also going to perform a subtraction operation.

Anyways, like the previous program, we are going to use any specific kind of addressing mode for this program.

Input:

For this program also we are going to need in total seven memory locations. Starting from the 2000H memory location, we are going to store the first 16-bit hexadecimal number; AC82H.

And then in the 2002H and 2003H memory location, we are going to store the second 16-bit hexadecimal number i.e. 123BH, and in finally in the 2004H memory location, we are going to store the 8-bit hexadecimal number 24H.

Now, in order to store the result, we can use 2005H and 2006H memory location.

Program:

LHLD 2000H //the content of 2000H and 2001H memory location will be copied to HL register pair

XCHG //using XCHG instruction we are going to copy the content of HL register pair to DE pair

LHLD 2002H //now we load the content of 2002H into HL register pair

DAD D// now using DAD instruction we are going to add the content of HL register pair and DE register pair

MOV A, L //after performing addition operation you’ll need to copy the LSB to accumulator

MOV D, H //and then we’ll copy the MSB in D or any other general purpose register

LXI H, 2004H //using LXI we’ll point HL register to 2004H memory location

SUB M // and then we will perform the subtraction operation of the LSB with the 8-bit hexadecimal number

STA 2005H //next, using STA we’ll copy the content of accumulator in 2005H memory location

MOV A, D // now we’ll move the MSB to accumulator so that we could store it in a memory location

STA 2006H //finally we’ll store the MSB in 2006H memory location

HLT

 

Programming Details
Memory Location OPCODE Operand Label Hex Code
2007 LHLD 2000H 2AH
2008 00H
2009 20H
200A XCHG EBH
200B LHLD 2AH
200C 02H
200D 20H
200E DAD D 19H
200F MOV A,L 7DH
2010 MOV D,H 54H
2011 LXI H,2004 21H
2012 04H
2013 20H
2014 SUB M 96H
2015 STA 2005 32H
2016 05H
2017 20H
2018 MOV A,D 7AH
2019 STA 2006 32H
201A 06H
201B 20H
201C HLT 76H

About the author

Ayan