# 8085 program to add numbers in an array

• Last Updated : 05 Feb, 2019

Problem – Write an assembly language program to add hexadecimal numbers stored in continuous memory or in an array.

Assumption – Suppose the size of the array is stored at memory location 2050 and the base address of the array is 2051. The sum will be stored at memory location 3050 and carry will be stored at location 3051.

Example –

Algorithm –

1. Load the base address of the array in HL register pair.
2. Use the size of the array as a counter.
3. Initialise accumulator to 00.
4. Add content of accumulator with the content stored at memory location given in HL pair.
5. Decrease counter on each addition.

Program –

2000LDA 2050A <- [2050]
2003MOV B, AB <- A
2004LXI H, 2051H <- 20 and L <- 51
2007MVI A, 00A <- 00
2009MVI C, 00C <- 00
200BADD MA <- A+M
200CINR LM <- M+1
200DJNC 2011
2010INR CC <- C+1
2011DCR BB <- B-1
2012JNZ 200B
2015STA 30503050 <- A
2018MOV A, CA <- C
2019STA 30513051 <- A
201CHLTTerminates the program

Explanation –

1. LDA 2050: load accumulator with content of location 2050
2. MOV B, A: copy contents of accumulator to register B
3. LXI H, 2051: store 20 to H register and 51 to L register
4. MVI A, 00: store 00 to accumulator
5. MVI C, 00: store 00 to register C
6. ADD M: add accumulator with the contents of memory location given in HL register pair
7. INR L: increase address by 1
8. JNC 2011: if not carry, jump to location 2011 otherwise to the location given in PC
9. INR C: increase content of register C by 1
10. DCR B: decrease content of register B by 1
11. JNZ 200B: if not zero, jump to location 200B otherwise to the location given in PC
12. STA 3050: store contents of accumulator to memory location 3050
13. MOV A, C: copy contents of register C to accumulator
14. STA 3051: store contents of accumulator to memory location 3051
15. HLT: terminates the program
My Personal Notes arrow_drop_up