# 8085 program to add two consecutive bytes of an array

MicroprocessorMicrocontroller8085

Here we will see how we can add two consecutive elements in an array using 8085.

## Problem Statement

Write 8085 program to add two consecutive elements of an array and store them in the same location. The carry will be placed at bottom of the other byte. The numbers are stored from location 8001. The size of array is stored at 8000.

## Discussion

Here we will solve this problem by using one subroutine. That will add two consecutive numbers and stored them into correct position. That subroutine will be called multiple times to add all consecutive pairs. The task will be followed half of the number of elements. So we are taking the count, then rotate it to the right to make it half. We are rotating through carry. if the carry is already high it may store different result, so we are clearing the carry by using STC and CMC instructions.

Data

8000
0A
8001
E9
8002
D3
8003
61
8004
8005
2A
8006
1F
8007
5D
8008
A6
8009
A9
800A
35

## Program

HEX Codes
Labels
Mnemonics
F000
21, 00, 80

LXI H,8000
Point to get array size
F003
7E

MOV A,M
F004
37

STC
set carry flag
F005
3F

CMC
complement carry flag
F006
0F

RRC
rotate right through carry
F007
47

MOV B,A
Store A into B
F008
23
LOOP
INX H
point to next location
F009
CD, 11, F0

F00C
05

DCR B
Decrease B by 1
F00D
C2, 08, F0

JNZ LOOP
F010
76

HLT
Terminate the program
F011
0E, 00
MVI C,00H
clear C flag
F013
7E

MOV A,M
load first number from memory to A
F014
23

INX H
point to next location
F015
86

F016
D2, 1A, F0

JNC STORE
F019
0C

INR C
else increase C by 1
F01A
71
STORE
MOV M,C
store C into memory
F01B
2B

DCX H
point to previous location
F01C
77

MOV M,A
store A into memory
F01D
23

INX H
point to next location
F01E
C9

RET
return from subroutine

## Output

Data

8001
BC
8002
01
8003
0E
8004
01
8005
49
8006
00
8007
03
8008
01
8009
DE
800A
00

Updated on 30-Jul-2019 22:30:26