You will have to take 5 numbers between 0-9 as input and calculate their sum. Keep in mind that the input you are taking is a character. You somehow have to convert it to the corresponding number. Then you will print strings based on the value of the sum you calculated. You will have to follow the pseudo-code given below –
While taking the inputs, you will have to print appropriate input prompts. You will first print ”Enter the first number: ” (there is a space after colon) and take the input in the same line. Then in the next line you will print ”Enter the second number: ” and take the second number as input in the same line. You will do the same for third, fourth and fifth numbers
Marks
DATA SEGMENT
 
MSG_ENTER1    DB 10,13,"Enter the first number: $"
MSG_ENTER2    DB 10,13,"Enter the second number: $"
MSG_ENTER3    DB 10,13,"Enter the 3 number: $"
MSG_ENTER4    DB 10,13,"Enter the 4 number: $"
MSG_ENTER5    DB 10,13,"Enter the 5 number: $"
MSG_sum    DB 10,13,"Sum: $"
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
    MOV AX,DATA
    MOV DS,AX
    MOV ES,AX    
    XOR BX, BX            ; sum in BL
 
    LEA DX,MSG_ENTER1        ; "Enter ..."
    MOV AH,9            ; Display string
    INT 21H
    MOV AH,1            ; Waiting for a key press
    INT 21H
; AL = ASCII code of key pressed
    SUB AL, 30H            ; AL NUMBER
    add BL,AL
    LEA DX,MSG_ENTER2        ; "Enter ..."
    MOV AH,9            ; Display string
    INT 21H
    MOV AH,1            ; Waiting for a key press
    INT 21H
; AL = ASCII code of key pressed
    SUB AL, 30H            ; AL NUMBER
    add BL,AL
    LEA DX,MSG_ENTER3        ; "Enter ..."
    MOV AH,9            ; Display string
    INT 21H
    MOV AH,1            ; Waiting for a key press
    INT 21H
; AL = ASCII code of key pressed
    SUB AL, 30H            ; AL NUMBER
    add BL,AL
    LEA DX,MSG_ENTER4        ; "Enter ..."
    MOV AH,9            ; Display string
    INT 21H
    MOV AH,1            ; Waiting for a key press
    INT 21H
; AL = ASCII code of key pressed
    SUB AL, 30H            ; AL NUMBER
    add BL,AL
    LEA DX,MSG_ENTER5        ; "Enter ..."
    MOV AH,9            ; Display string
    INT 21H
    MOV AH,1            ; Waiting for a key press
    INT 21H
; AL = ASCII code of key pressed
    SUB AL, 30H            ; AL NUMBER
    add BL,AL
    MOV    AH,9        
    LEA  DX,MSG_sum   
    INT    21H
    cmp     bl,10
    jc     final   
; Calculate tens
    XOR AX,AX            ; AX = 0 before multiplication AX=0
    MOV CL,10
    MOV AL, bL        ;  
    div CL            ; <number>/10
    MOV DX,AX        ; dl = tens    
    
    add dl,30h
    mov  ah,2h     
    int  21h
    
    mov dl,dh
    jmp l1
final:    
    mov dx,bx
l1:    
    add dl,30h
    mov  ah,2      
    int  21h
    mov ah, 4ch
    int 21h
CODE ENDS
END START
Comments