- 2074 Bhadra · 8 marks
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)
Related questions
- 8085 ALP: compare two tables of 16-bit data · Microprocessor, chapter 2
- 8085 ALP: add upper and lower nibbles · Microprocessor, chapter 2
- 8085 ALP: multiplication table of a number · Microprocessor, chapter 2
- 8085 ALP: interchange two bits of bytes · Microprocessor, chapter 2
- 8085 ALP: copy data within a range · Microprocessor, chapter 2
- 8085 ALP: transfer data with more than 3 ones · Microprocessor, chapter 2
- C program: sum of two 8-bit BCD numbers · Embedded System, chapter 9
- Townsend's first and second coefficients from data · High Voltage Engineering, chapter 6
- Time class: add two objects · Object Oriented Programming, chapter 1
- Add objects of two different classes · Object Oriented Programming, chapter 4 · asked 2×