Tuesday, 28 July 2015

Write a program to (a) display a "?", (b) read two decimal digits whose sum "is less than 10, (c) display them and their sum on the next line, with an appropriate message In assembly Language Using Procedure/Function.

Write a program to (a) display a "?", (b) read two decimal digits
whose sum "is less than 10, (c) display them and their sum on the
next line, with an appropriate message.
Sample execution:
?27
THE SUM OF 2 AND 7 IS 9
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
TAG: EASY, 8086 MICROPROCESSOR, ASSEMBLY LANGUAGE CHAPTER 4 , PROGRAMMING EXERCISE , FUNCTION/PROCEDURE .

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    STR1 DB 0AH,0DH,'THE SUM OF '
    FIRSTNUM DB ?
    STR2 DB ' AND '
    SECONDNUM DB ?
    STR3 DB ' IS '
    ANS DB ?
    STR4 DB ' $'
.CODE
MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    CALL MSG_PROMPT
    CALL INPUT_FUNC
    CALL CALCULATION_FUNC
    CALL OUTPUT_FUNC

    MOV AH,4CH
    INT 21H
 
    MAIN ENDP

MSG_PROMPT PROC
 
    MOV AH,2
    MOV DL,3FH
    INT 21H
 
    RET
    MSG_PROMPT ENDP

INPUT_FUNC PROC
 
    MOV AH,1
    INT 21H
    MOV BL,AL
    MOV FIRSTNUM,AL
    INT 21H
    MOV SECONDNUM,AL
 
    RET
    INPUT_FUNC ENDP

CALCULATION_FUNC PROC  
 
    ADD BL,AL
    SUB BL,30H
    MOV ANS,BL
 
    RET
    CALCULATION_FUNC ENDP

OUTPUT_FUNC PROC  
 
    MOV AH,9
    LEA DX,STR1   ;VARIABLE PRINTING FIRST TO LAST
    INT 21H
 
    RET
    OUTPUT_FUNC ENDP

END MAIN

No comments:

Post a Comment