GATE / CS ARCHIVE

GATE CSE 1994 / QUESTION 10

8085 packed BCD addition

Computer Organization & Architecture · Instructions & Addressing Modes · Full GATE CSE 1994 paper

GATE 1994, Q10 5 marks · Descriptive
Report issue

Instructions & Addressing Modes

Question 10, GATE 1994: Write 8085 assembly to add two unsigned 16-bit packed 8-4-2-1 BCD operands in register pairs BC and DE. Place the result in BC; the higher register contains the higher-order decimal digits.
Tap to enlarge
Answer & solution

Answer: Use ADD/DAA for the low byte and ADC/DAA for the high byte; final CY is decimal overflow. (no official key was published)

1. Each packed byte holds two decimal digits. First add C and E in A; DAA adjusts the binary sum into valid packed BCD and supplies the carry into the next two digits.

2. MOV C,A saves the low result without changing flags. MOV A,B also preserves the carry, allowing ADC D to add high bytes plus the low-byte decimal carry.

3. A second DAA adjusts the upper digits. MOV B,A preserves the final carry flag. BC now contains the lowest four decimal digits.

4. A sum above 9999 cannot fit in BC. The fifth digit is final CY (0 or 1); the question supplies no separate overflow destination. This limitation must not be concealed.

Code

MOV A,C
ADD E
DAA
MOV C,A
MOV A,B
ADC D
DAA
MOV B,A

Original paper, page 5