Skip to main content

8085 ALP: add two tables, sum and carry

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.

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.

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

        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.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Microprocessor chapter 2 questions →