Aim To write a program to add two BCD numbers.

Description One 8-bit packed BCD number is available in the memory location 4300H and another number is available in the memory location 4301H. Result is available in the location 4302H and carry in 4303H.

Algorithm
1. Get the BCD numbers from the memory locations.
2. Add the BCD numbers with the help of DAA.
3. Store the sum and carry in the memory.

Program
4100: 90 43 00         MOV DPTR,#4300H          ;Address of first BCD number
4103: 79 00              MOV R1,#00                       ;Carry is reset
4105: E0                   MOVX A,@DPTR                  ; First number in A
4106: A3                   INC DPTR                            ; Pointing to second number
4107: F8                   MOV R0,A                            ; First number in R0
4108: E0                   MOVX A,@DPTR                  ; Second number in A
4109: 28                   ADD A,R0                             ; Add both numbers
410A: D4                   DA A                                     ; Convert to BCD
410B: 50 01             JNC NOC (410E)                 ; If no carry, skip
410D:09                    INC R1                                 ; Else increment carry
410E: A3         NOC: INC DPTR
410F: F0                   MOVX @DPTR,A                ; Result in destination address
4110: E9                   MOV A,R1                          ; Carry in A
4111: A3                   INC DPTR
4112: F0                   MOVX @DPTR,A                ; Store carry
4113: 80 FE    HLT: SJMP HLT (4113)              ; Halt

Procedure
1. Enter the program in memory locations starting from 4100H.
2. Enter data in memory locations 4300H and 4301H.
3. Execute the program and verify the sum in memory location 4302H and carry in 4303H.

Test data
Input: 4300: 75 4301: 65 Output: 4302: 40 4303: 01

0 comments