title: How to Add 4 digit numbers and display the sum in Assembly using one variable?
body: <p>I am using EMU8086. How do I add 4 digit numbers and display the sum in Assembly using one variable?</p>
  
  <pre><code>DATA SEGMENT
       MSG1 DB "ENTER NUMBER WITH FOUR DIGITS : $"
       MSG2 DB 10,13,"RESULT : $"
       D1 DB ? 
       D2 DB ?
       D3 DB ?
       D4 DB ?
       SUM DB ?
       RES  DB 10 DUP ('$')
  DATA ENDS
  CODE SEGMENT 
      ASSUME DS:DATA CS:CODE
  START:
        MOV AX,DATA
        MOV DS,AX
  
        LEA DX,MSG1         
        MOV AH,9
        INT 21H     
  
        MOV AH,1
        INT 21H
        SUB AL,30H
        MOV AH,0
        MUL AL
        MOV D1,AL
  
        MOV AH,1
        INT 21H
        SUB AL,30H
        MOV AH,0
        MUL AL
        MOV D2,AL
  
        MOV AH,1
        INT 21H
        SUB AL,30H
        MOV AH,0
        MUL AL
        MOV D3,AL
  
        MOV AH,1
        INT 21H
        SUB AL,30H
        MOV AH,0
        MUL AL
        MOV D4,AL
  
        ADD AL,D3
        ADD AL,D2
        ADD AL,D1      
        MOV SUM,AL 
  
        LEA SI,RES
        CALL HEX2DEC
  
        LEA DX,MSG2
        MOV AH,9
        INT 21H
  
        LEA DX,RES
        MOV AH,9
        INT 21H 
  
        MOV AH,4CH
        INT 21H     
  CODE ENDS
  HEX2DEC PROC NEAR
      MOV CX,0
      MOV BX,10
  
  LOOP1: MOV DX,0
         DIV BX
         ADD DL,30H
         PUSH DX
         INC CX
         CMP AX,9
         JG LOOP1
  
         ADD AL,30H
         MOV [SI],AL
  
  LOOP2: POP AX
         INC SI
         MOV [SI],AL
         LOOP LOOP2
         RET
  HEX2DEC ENDP
  END START
  </code></pre>