# Add Hexadecimal numbers stored in Continuous Memory or in an Array

Here, we are going to learn how to add Hexadecimal numbers stored in Continuous Memory or in an Array?
Submitted by Deepanshi Mittal, on October 30, 2018

Problem statement:

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

Assumption: Let 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.

Algorithm:

1. Load the base address of the array in HL register pair.
2. Size of the array is used as a counter.
3. Initialize 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:

```    2000    LDA 2050
2003    MOV B,A
2004    LXI H,2051
2007    MVI A,00
2009    MVI C,00
200C    INR M
200D    JNC 2011
2010    INR C
2011    DCR B
2012    JNZ 200B
2015    STA 3050
2018    MOV A,C
2019    STA 3051
201C    HLT
```

Explanation:

• LDA 2050: load accumulator with content of location 2050
• MOV B, A: copy contents of accumulator to register B
• LXI H, 2051: store 20 to H register and 51 to L register
• MVI A, 00: store 00 to accumulator
• MVI C, 00: store 00 to register C
• ADD M: add accumulator with the contents of memory location given in HL register pair
• INR M: increase M by 1
• JNC 2011: if not carry, jump to location 2011 otherwise to the location given in PC
• INR C: increase content of register C by 1
• DCR B: decrease content of register B by 1
• JNZ 200B: if not zero, jump to location 200B otherwise to the location given in PC
• STA 3050: store contents of accumulator to memory location 3050
• MOV A, C: copy contents of register C to accumulator
• STA 3051: store contents of accumulator to memory location 3051
• HLT: terminates the program

What's New

Top Interview Coding Problems/Challenges!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates