Saturday, 3 March 2018

Read two decimal digits whose sum is less or big than 10, display them and their sum on the next line with an appropriate message in Assembly Language.

;Write a program to 
;(a) read two decimal digits whose sum is less or big than 10, 
;(b) display them and their sum on the next line with an appropriate message.


.MODEL SMALL
.STACK 100H   
.DATA
    a DB 0
    b DB 0
    MSG1 DB 'Enter a: $'
    MSG2 DB 0AH, 0DH, 'Enter b: $'                     ; variable declaration
    MSG3 DB 0AH, 0DH, 'Sum of a and b is: $'
.CODE
MAIN PROC  ;PROC = Procedure
    MOV AX, @DATA    ; initialize data segment
    MOV DS, AX
   
    LEA DX, MSG1    ; LEA = Load Effective Address      Compute address of value
    MOV AH, 9       ; Output a String
    INT 21H
   
   
    MOV AH, 1   ; INPUT FUNCTION 1
    INT 21H     ; INT = Interupt
    MOV a, AL
   
    ;MOV BH, AL 
   
    LEA DX, MSG2    ; LEA = Load Effective Address      Compute address of value
    MOV AH, 9       ; Output a String
    INT 21H
   
   
    MOV AH, 1   ; INPUT FUNCTION 2
    INT 21H     ; INT = Interupt
    MOV b, AL
   
    ADD AL, a
    MOV AH,0    ; AX = AH, AL
    AAA         ; AAA = Adjust After Addition (first digit is saved in AH register and second digit is saved in AL register)   
   
    ADD AH,30H
    ADD AL,30H
   
    MOV BX,AX    ; Since the AH register is used again and again. We cannot lose the result in AH and AL register, So to save the to be printed value in BH and BL register. By moving AX to BX.
   
    LEA DX,MSG3
    MOV AH,9
    INT 21H     
   
    MOV AH,2
    MOV DL,BH
    INT 21H
   
    MOV AH,2
    MOV DL,BL
    INT 21H
   
   
   EXIT:
   MOV AH, 4CH
   INT 21H
   MAIN ENDP
END MAIN

No comments:

Post a Comment