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.

D001 | 08 H |

D002 | 12 H |

D003 | 74 H |

D004 | 34 H |

D005 | 04 H |

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

**E000 H = C6 H.**

**Flow Chart of Program**

**Assembly Language Program**

Label | instruction | Comment | Operation |
---|---|---|---|

LDA D000H | A = contents of location D000H | A = 05H | |

MOV C, A | Initialize counter | C = 05H | |

XRA A | Sum = 0 | A = 00H | |

LXI H, D001H | Initialize HL as a memory pointer for the series | H = D0H L = 01H | |

L1: | ADD M | Sum in A = Sum in A + M | A = A + M |

INX H | Increment pointer | HL = HL + 1 | |

DCR C | Decrement counter | C = C -1 | |

JNZ L1 | If the counter is not equal to 0 then repeat | ||

STA E000H | Store the result at memory location E000H | E000H = C6H | |

HLT | Terminate program execution | Stop |

**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.

D001H | 9A H |

D002H | 52 H |

D003H | 89 H |

D004H | 3E H |

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

**E000 H = B3 H ,E001 H= 01 H**

**Flow Chart of Program**

**Assembly Language Program**

Label | Instruction | Comment | Operation |
---|---|---|---|

LDA D000H | A = contents of location D000H | A = 04 H | |

MOV C, A | Initialize counter | C = 04 H | |

XRA A | sum = 0 | A = 00 H | |

XRA B | sum in B = 0 | B = 00 H | |

LXI H, D001H | Initialize HL as a memory pointer for the series | H = D0 H L = 01 H | |

L1: | ADD M | Sum in A = Sum in A + M | A = A + M |

JNC L2 | Check for carry | Is CY = 1 | |

INR B | Carry is incremented as MSB in register B | B = B + 1 | |

L2: | INX H | Increment pointer | HL = HL + 1 |

DCR C | Decrement counter | C = C – 1 | |

JNZ L1 | If the counter is not equal to 0 then repeat | ||

STA E000H | Store the result at memory location E000H | E000H = B3H | |

MOV A, B | Store the MSB of the result in register B | A = B = 01 H | |

STA E001H | Store the result at memory location E001H | E001H = 01 H | |

HLT | Terminate program execution | Stop |