Advertisement
madmaxhasan

Add and Print two digit number

Feb 3rd, 2018
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .MODEL SMALL
  2. .STACK 100
  3.  
  4. .DATA
  5.    
  6.     NUM1 DB ?
  7.     NUM2 DB ?
  8.     RESULT DB ?
  9.     MSG1 DB "ENTER FIRST NUMBER TO ADD : $"
  10.     MSG2 DB 10,13,"ENTER SECOND NUMBER TO ADD : $"
  11.     MSG3 DB 10,13,"RESULT OF ADDITION : $"
  12.    
  13. .CODE
  14.  
  15. MAIN PROC
  16.    
  17.     MOV AX, @DATA
  18.     MOV DS, AX
  19.    
  20.     LEA DX, MSG1
  21.     MOV AH, 9
  22.     INT 21H
  23.    
  24.     MOV AH, 1
  25.     INT 21H
  26.     SUB AL, 30H
  27.     MOV NUM1, AL
  28.    
  29.     LEA DX, MSG2
  30.     MOV AH, 9
  31.     INT 21H
  32.    
  33.     MOV AH, 1
  34.     INT 21H
  35.     SUB AL, 30H
  36.     MOV NUM2, AL
  37.    
  38.     ADD AL, NUM1            ; ADDING TWO NUMBERS NUM1 AND ACCUMALOTOR VALUE WHICH HAVE THE NUM2 VALUE
  39.    
  40.     MOV RESULT, AL
  41.    
  42.     MOV AH, 0               ; REMOVE GARBAGE FROM AH ( ACCUMALATOR HIGH )
  43.     AAA                     ; What AAA exactly does is it converts the result into BCD form and first digit is saved in
  44.                             ; AH register and second digit is saved in AL register.
  45.    
  46.     ADD AH, 30H             ; By adding 30H to BCD will Convert it to ASCII code which will print the digit (number) on screen.
  47.     ADD AL, 30H
  48.    
  49.     MOV BX, AX              ; Since the AH register is used again and again. We cannot lose the result in AH and AL register,
  50.                             ; So to save the to be printed value in BH and BL register. By moving AX to BX.
  51.    
  52.     LEA DX, MSG3
  53.     MOV AH, 9
  54.     INT 21H
  55.    
  56.     MOV AH, 2               ; OUTPUT FIRST CHARACTER ON BASE REGISTOR
  57.     MOV DL, BH              ; PRINT BASE REGISTOR HIGHER PORTION ( BH )
  58.     INT 21H
  59.    
  60.     MOV AH, 2               ; OUTPUT FIRST CHARACTER ON BASE REGISTOR
  61.     MOV DL, BL              ; PRINT BASE REGISTOR LOWER PORTION ( BL )
  62.     INT 21H
  63.    
  64.     MOV AH, 4CH
  65.     INT 21H
  66.    
  67. MAIN ENDP
  68. ENDS PROC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement