---
title: "8085 ALP: add two tables, sum and carry"
subject: "Microprocessor"
chapter: 2
key: "semester_4/microprocessor:alp-8085-add-two-tables"
source: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8085-add-two-tables
site: BCT Engineering
---

# 8085 ALP: add two tables, sum and carry

Microprocessor · Chapter 2: Programming with 8085 Microprocessor

- Asked in: 2074 Bhadra, 8 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8085-add-two-tables
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-2

## Question

There are two tables holding twenty data whose starting address is 9000H and 9020H respectively. Write a program to add the content of first table with the content of second table having same array index. Store sum and carry into the third and fourth table indexing from 9040H and 9060H respectively.

## Short answer

For each of 20 elements, add table1[i] and table2[i] (at 9000H+i and 9020H+i). Store sum at 9040H+i; obtain carry by MVI A,00H then RAL to get 00H or 01H, store at 9060H+i. Tables share same page; offset by 20H each.

## Answer

**Method:** all four tables are in page 90H, 20H bytes apart (table size 20 = 14H), so only L has to change: H stays 90H and L is used as the index. Table 2 is at L + 20H, sum at L + 40H and carry at L + 60H. The carry is obtained as 00H or 01H by `MVI A,00H` followed by `RAL` (MVI does not disturb CY).


```asm
        LXI H,9000H     ; H = 90H (fixed), L = index 00H..13H
        MVI C,14H       ; 20 elements
LOOP:   MOV B,M         ; B = element of table 1 (9000H + i)
        MOV A,L
        ADI 20H         ; L = L + 20H -> table 2
        MOV L,A
        MOV A,B
        ADD M           ; A = table1[i] + table2[i], CY = carry
        MOV B,A         ; B = sum
        MVI A,00H       ; MVI does not change CY
        RAL             ; A = 00H or 01H = carry
        MOV D,A         ; D = carry
        MOV A,L
        ADI 20H         ; L -> table 3 (9040H + i)
        MOV L,A
        MOV M,B         ; store sum
        ADI 20H         ; L -> table 4 (9060H + i)
        MOV L,A
        MOV M,D         ; store carry
        SUI 5FH         ; A = (i + 60H) - 5FH = i + 1
        MOV L,A         ; HL -> next element
        DCR C
        JNZ LOOP
        HLT
```


**Result:** for each i, 9040H+i has the 8-bit sum and 9060H+i has 01H if the sum exceeded FFH, otherwise 00H.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Why does the program change only L and keep H = 90H throughout?
   A. Because H cannot be changed inside a loop
   B. Because all four tables lie in page 90H, 20H bytes apart, so only the low address byte differs
   C. Because the tables are 20 bytes long and 20 fits in L
   D. Because ADD M only uses L as the address
   Answer: B. Tables start at 9000H, 9020H, 9040H and 9060H, so the high byte is always 90H and adding 20H to L moves to the next table. (Key point: All tables are in page 90H, 20H apart, so only L changes)

2. After ADD M, how does the program get the carry as 00H or 01H?
   A. MVI A,00H then RAL; MVI does not change CY, and RAL moves CY into bit 0
   B. XRA A then RAL; XRA keeps the carry flag
   C. MOV A,CY directly copies the carry flag
   D. JNC is used to store 01H whenever there is no carry
   Answer: A. MVI A,00H clears A without touching CY, and RAL rotates CY into bit 0, giving 01H if there was a carry and 00H otherwise. (Key point: Carry is obtained as 00H/01H with MVI A,00H then RAL)

3. Why is the counter loaded with MVI C,14H?
   A. Because each table is 14H bytes apart
   B. Because 14H is the address of the last element
   C. Because 14H is the size of the sum table plus the carry table
   D. Because there are twenty elements and 20 decimal = 14H
   Answer: D. The tables hold twenty data, and 20 in decimal is 14H, so the loop runs 14H times. (Key point: Counter C = 14H because there are 20 (decimal) elements)

4. After storing the carry, A = i + 60H. Why does the program do SUI 5FH and MOV L,A?
   A. To go back to table 3 to check the sum
   B. To clear the carry flag before the next ADD
   C. To get i + 1, so HL points to the next element of table 1
   D. To subtract the carry from the sum
   Answer: C. (i + 60H) - 5FH = i + 1, so L moves to the next element of table 1 (9000H + i + 1) for the next iteration. (Key point: SUI 5FH turns i + 60H back into i + 1 to point to the next element)

## Related in Microprocessor

- [8085 ALP: compare two tables of 16-bit data](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-compare-tables-1ffffh) — Microprocessor, chapter 2
- [8085 ALP: add upper and lower nibbles](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-add-nibbles) — Microprocessor, chapter 2
- [8085 ALP: multiplication table of a number](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-multiplication-table) — Microprocessor, chapter 2
- [8085 ALP: interchange two bits of bytes](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-interchange-bits) — Microprocessor, chapter 2
- [8085 ALP: copy data within a range](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-copy-range) — Microprocessor, chapter 2
- [8085 ALP: transfer data with more than 3 ones](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-ones-greater-than-3) — Microprocessor, chapter 2

## Related in other subjects

- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [Townsend's first and second coefficients from data](https://www.bctengineer.com/question.md?key=semester_8%2Fhigh_voltage_engineering%3Atownsend-first-second-coefficients) — High Voltage Engineering, chapter 6
- [Time class: add two objects](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Atime-class-add-objects) — Object Oriented Programming, chapter 1
- [Add objects of two different classes](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afriend-add-two-class-objects) — Object Oriented Programming, chapter 4, asked 2×
