TITLE   Addition of two integers in ASCII form   ASCIIADD.ASM
COMMENT |
        Objective: To demonstrate addition of two integers
                   in the ASCII representation.
            Input: None.
|          Output: Displays the sum.
.MODEL SMALL
.STACK 100H
.DATA
sum_msg   DB  'The sum is: ',0
number1   DB  '1234567890'
number2   DB  '1098765432'
sum       DB  10 DUP (' '),0 ; add NULL char. to use PutStr

.CODE
INCLUDE io.mac
main  PROC
      .STARTUP
      ; SI is used as index into number1, number2, and sum
      mov     SI,9           ; SI points to rightmost digit
      mov     CX,10          ; iteration count (# of digits)
      clc                    ; clear carry (we use ADC not ADD)
add_loop:
      mov     AL,number1[SI]         
      adc     AL,number2[SI]
      aaa                    ; ASCII adjust
      pushf                  ; save flags because OR
      or      AL,30H         ;  changes CF that we need
      popf                   ;  in the next iteration
      mov     sum[SI],AL     ; store the sum byte
      dec     SI             ; update SI
      loop    add_loop
      PutStr  sum_msg        ; display sum
      PutStr  sum
      .EXIT
main  ENDP
      END     main
