Add two 16-bit numbers in 8085

In this program, we are going to write an assembly language program to add two 16-bit numbers in 8085 microprocessor with a program flow chart and explanation of the program.

Add two 16-bit numbers in 8085

Program Statement

Write a program to add the 16-bit number in memory locations D000H and D001H with the 16-bit number in memory locations D002H and D003H. The most significant 8 bits of the two numbers to be added are in memory locations D001H and D003H. Store the result in memory locations D004H and D005H with the most significant byte in memory location D005H

Explanation of Program

  • We have two 16-bit numbers. Let the two numbers be 1234H and 4321H.
  • We have to add the word at memory locations D000H and D001H with the word at memory locations D002H and D003H.
  • For computing the addition there are two methods.
  • In the first method, we will add the two LSBs and the two MSBs separately and store the result.
  • In the second method, we will store the two numbers in the register pairs DE and HL. Then using the DAD instruction we will add the two 16-bit numbers. The result of the addition will be stored in the HL register pair.
    • D000H = 34H, D001H = 12H, D002H = 21H, D003H = 43H
    • Result = 1234 H + 4321 H = 5555 H
    • D004H = 55H and D005H = 55H

Method 1

  • In the first method, we will add the two LSBs and the two MSBs separately and store the result.

Assembly Language Program

InstructionCommentOperation
LHLD D000HLoad the first 16-bit numbers in the HL register pair. H = 12H, L = 34H
XCHGsave the 16-bit number in the DE register pair.D = 12H, E = 34H
LHLD D002HLoad the second 16-bit numbers in the HL register pair. H = 43H, L = 21H
MOV A, ELoad the lower byte of the first number in the accumulatorA = 34H
ADD LAdd the two lower bytesA = A + L = 34 + 21
A = 55H
MOV L, AStore the result in the L registerL = 55H
MOV A, DLoad the higher byte of the first number in the accumulatorA = 12H
ADC HAdd the two higher bytes along with the carry of the lower byte addition.A= A + H + CY
A = 12 + 43 + 0
A = 55H
MOV H, AStore the result in the H registerH = 55H
SHLD D004HStore the 16-bit result in memory locations D004H and D005H.D004H = 55H
D005H = 55H
HLTTerminate program executionStop

Flow Chart of Program

Add two 16-bit numbers in 8085 flow chart 1

Method 2

  • In the second method, we will store the two numbers in the register pairs DE and HL. Then using the DAD instruction we will add the two 16-bit numbers. The result of the addition will be stored in the HL register pair.

Assembly Language Program

InstructionCommentOperation
LHLD D000HLoad the first 16-bit numberH = 12H, L = 34H
XCHGSave the first 16-bit number in the DE register pair.D = 12H, E = 34H
LHLD D002HLoad the second 16-bit numberH = 43H, L = 21H
DAD Dadd the two 16-bit numbers.HL = HL + DE
HL = 4321 + 1234
HL = 5555H
H = 55H, L = 55H
SHLD D004HStore the 16-bit result.D004H= 55H
D005H = 55H
HLTTerminate program executionStop

Flow Chart of Program

Add two 16-bit numbers in 8085 flow chart 2

Sr. No.Name of the 8085 Programs
1.Write a program to load the data into the accumulator and any register.
2.Write a program to exchange the contents of memory locations.
3.Add two 8-bit numbers.
4.Subtract two 8-bit numbers.
5.Add two 16-bit numbers.
6.Subtract two 16-bit numbers
7.Find the 1’s complement of a Number
8.Find the 2’s complement of a Number
9.8085 Program To Mask The Lower Nibble
10.8085 Program To Mask The Upper Nibble
11.8085 program to pack the two unpacked BCD numbers
12.8085 program to Unpack the two packed BCD numbers
13.8085 program to find the sum of a series of 8-bit numbers
14.8085 Program to sort the numbers in ascending order
15.8085 Program to sort the numbers in Descending order
16.8085 Program to Multiply Two 8-bit Numbers
17.8085 Program to Divide 16-bit number by 8-bit number
18.8085 Program to Find the Number of Negative Numbers in Array
19.8085 Program to Find Maximum Number in Array
20.8085 Program to count the number of 1’s in a register

Hello friends, my name is Trupal Bhavsar, I am the Writer and Founder of this blog. I am Electronics Engineer(2014 pass out), Currently working as Junior Telecom Officer(B.S.N.L.) also I do Project Development, PCB designing and Teaching of Electronics Subjects.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

telegram logo Join Our Telegram Group!