page 60,80
title sum
s_seg segment stack
db 100 DUP (?)
s_seg ends
    
d_seg segment
    Buff        db      10
    Lenth       db      0
    Num         db      8 DUP (0)
    X1          dw      0
    X2          dw      0
    Temp        dw      1
    Sum         dw      0   
    Mess1       db      "Enter First Number :",10,13,'$'
    Mess2       db      "Enter Second Number :",10,13,'$'
    Result      db      "The Sum is :  $" 
    NewLine     db      10,13,'$'
d_seg ends
c_seg segment
;****************************************************
    main proc     far
    assume     cs:c_seg,ds:d_seg,ss:s_seg
      mov     ax,d_seg
      mov     ds,ax
;******  Print first Message *************
      lea dx,Mess1
      mov ah,9
      int 21h
;******************************************
    call AsciToInt  ; Change the entered string number to an integer
    mov X1,di       ; the number is returned in di
;******  Print Second Message *************
    lea dx,Mess2
    mov ah,9
    int 21h
;******************************************
    call AsciToInt  ; Same as before
    mov X2,di
    mov ax,X1
    add ax,X2
    mov Sum,ax      ;Sum contains the sum of the 2 numbers
    call IntToAsci  ; This will change the Sum to Ascii so we can print it
;*********** Print Result Message *****************************
    lea dx,Result
    mov ah,9
    int 21h
;********** Print the Sum ************************************
    mov dx,si   ; offset of Sum is returned in si
    mov ah,9
    int 21h
;********* Just a new Line ************************
    lea dx,NewLine
    mov ah,9
    int 21h
;*********** The End *********************
      mov     ax,4c00h
      int     21h
 main endp

;******  Program wich will change asci number to an integer **********
AsciToInt:
;********* Get an entered String Number **********
    lea dx,Buff
    mov ah,0Ah
    int 21h
;*************************************************    
    mov Temp,1
    xor bx,bx
    xor di,di
    mov bl,Lenth
    inc dx
    mov si,dx
NextChar:    
    xor ax,ax
    mov al,[si+bx] ; Get the first digit it is the right char
    sub al,30h      ;; change ascii char to its number
    mov cx,Temp
    mul cx          ; multiply first by 1 , second by 10 ,third by 100 etc ...
    add di,ax       ;add in di what we've got
    mov ax,10
    mul cx          ; mul ax by 10 for next char
    mov Temp,ax
    dec bx
    jnz NextChar

    lea dx,NewLine
    mov ah,9
    int 21h

    ret
    
;******Change Number to its Ascii *******************
IntToAsci:
    lea si,Buff     ;We use Buff for result
    add si,9        ; We will start by the right
    mov byte ptr [si],'$' ; Make an end of string at end of buffer
    dec si
    mov ax,Sum
    mov bx,10

NextDigit:
    xor dx,dx
    div bx      ;Div ax by 10 the result will be in ax and the rest in dx
    cmp ax,0    
    jz LastOne  ;May be we have finnished
    add dl,30h  ; the rest is what we want so add 30 to it to make it ascii
    mov [si],dl ; Put this ascii in the buffer
    dec si      ; Decrement the buffer for next char
    jmp NextDigit
LastOne:
    cmp dl,0    
    jz ThatsAll ; if dl is zero so we have finnished
    add dl,30h  ; The last digit
    mov [si],dl 
ThatsAll: 
Ret      
      c_seg ends
      end main