Statement: Add two 4 digit BCD numbers in HL and DE register pairs and store result in memory locations, 2300H and 2301H. Ignore carry after 16 bit.
Sample Problem:
(HL) =3629
(DE) =4738
Step 1 : 29 + 38 = 61 and auxiliary carry flag = 1
:.add 06
61 + 06 = 67
Step 2 : 36 + 47 + 0 (carry of LSB) = 7D
Lower nibble of addition is greater than 9, so add 6.
7D + 06 = 83
Result = 8367
Source program
MOV A, L : Get lower 2 digits of no. 1
ADD E : Add two lower digits
DAA : Adjust result to valid BCD
STA 2300H : Store partial result
MOV A, H : Get most significant 2 digits of number
ADC D : Add two most significant digits
DAA : Adjust result to valid BCD
STA 2301H : Store partial result
HLT : Terminate program execution.
(HL) =3629
(DE) =4738
Step 1 : 29 + 38 = 61 and auxiliary carry flag = 1
:.add 06
61 + 06 = 67
Step 2 : 36 + 47 + 0 (carry of LSB) = 7D
Lower nibble of addition is greater than 9, so add 6.
7D + 06 = 83
Result = 8367
Source program
MOV A, L : Get lower 2 digits of no. 1
ADD E : Add two lower digits
DAA : Adjust result to valid BCD
STA 2300H : Store partial result
MOV A, H : Get most significant 2 digits of number
ADC D : Add two most significant digits
DAA : Adjust result to valid BCD
STA 2301H : Store partial result
HLT : Terminate program execution.
Execellent
ReplyDeleteawesome bro
ReplyDelete