8085 program to find the sum of a series of 8-bit numbers

In this program, we will write an 8085 program to find the sum of a series of 8-bit numbers assuming the sum to be 8-bit in the 8085 microprocessor with a program flow chart and explanation of the program. Here we will see the two programs, one will be assuming the sum to be 8-bit and the other one will be assuming the sum to be 16-bit.

Program 1

8085 program to find the sum of a series of 8-bit numbers assuming the sum to be 8-bit

Program Statement

Calculate the sum of a series of numbers. The length of the series is in memory location D000H. The series begins from D001H. Assuming the sum to be an 8-bit number so that carry can be ignored. Store the result in memory location E000H.

Explanation of Program

  • We are given a series of numbers. The length of the series is stored at memory location D000 H. We will initialize register C as a counter with the length of the series.
  • We will initialize the accumulator with 00 H so that the sum can be stored in the accumulator.
  • The series begins at D001 H. So, we will initialize HL the register pair as a memory pointer to point the series.
  • Using the add instruction, add the contents, of the accumulator with the contents of the memory location pointed by the HL register pair. The result of this addition will be stored in the A register.
  • Then we will increment HL to point to the next memory location of the series. Decrement the count in register C. Continue this process till the count is zero i.e. all the numbers in the series are added.
  • Store the result at memory location E000 H.

Example: Let D000 05 H i.e. series is of 5 numbers.

D00108 H
D00212 H
D00374 H
D00434 H
D00504 H

Result = 08 H + 12 H + 74 H + 34 H + 04 = C6H

E000 H = C6 H.

Flow Chart of Program

8085 program to find the sum of a series

Assembly Language Program

LabelinstructionCommentOperation
LDA D000HA = contents of location D000HA = 05H
MOV C, AInitialize counterC = 05H
XRA ASum = 0A = 00H
LXI H, D001HInitialize HL as a memory pointer for the seriesH = D0H
L = 01H
L1:ADD MSum in A = Sum in A + MA = A + M
INX HIncrement pointerHL = HL + 1
DCR CDecrement counterC = C -1
JNZ L1If the counter is not equal to 0 then repeat
STA E000HStore the result at memory location E000HE000H = C6H
HLTTerminate program executionStop

Program 2

8085 program to find the sum of a series of 8-bit numbers assuming the sum to be 16-bit

Program Statement

Calculate the sum of a series of numbers. The length of the series is in memory location D000H. The series begins from D001H. Assuming the sum to be a 16-bit number and Storing the result in memory locations E000H and E001H.

Explanation of Program

  • We are given a series of numbers. The length of the series is stored at memory location D000 H. We will initialize register C as a counter with the length of the series.
  • We will initialize the accumulator with 00 H so that the sum can be stored in the accumulator. Also, initialize register B = 00 H so that the higher byte of the sum can be stored.
  • The series begins at D001 H. So, we will initialize HL the register pair as a memory pointer to point the series.
  • Using the add instruction, add the contents, of the accumulator with the contents of the memory location pointed by the HL register pair. The result of this addition will be stored in the A register.
  • Check for carry. If carry is 1 then increment register B.
  • Then we will increment HL to point to the next memory location of the series. Decrement the count in register C. Continue this process till the count is zero i.e. all the numbers in the series are added.
  • Store the result at memory locations E000 H and E001 H.

Example: Let D000 04 H i.e. series is of 4 numbers.

D001H9A H
D002H52 H
D003H89 H
D004H3E H

Result = 09A H +52 H + 89 H + 3E H = 1B3 H

E000 H = B3 H ,E001 H= 01 H

Flow Chart of Program

8085 program to find the sum of a series

Assembly Language Program

LabelInstructionCommentOperation
LDA D000HA = contents of location D000HA = 04 H
MOV C, AInitialize counterC = 04 H
XRA Asum = 0A = 00 H
XRA Bsum in B = 0B = 00 H
LXI H, D001HInitialize HL as a memory pointer for the seriesH = D0 H
L = 01 H
L1:ADD MSum in A = Sum in A + MA = A + M
JNC L2Check for carryIs CY = 1
INR BCarry is incremented as MSB in register BB = B + 1
L2:INX HIncrement pointerHL = HL + 1
DCR CDecrement counterC = C – 1
JNZ L1If the counter is not equal to 0 then repeat
STA E000HStore the result at memory location E000HE000H = B3H
MOV A, BStore the MSB of the result in register BA = B = 01 H
STA E001HStore the result at memory location E001HE001H = 01 H
HLTTerminate program executionStop
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

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!