Answer to Question #312242 in Assembler for barshon

Question #312242

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

1
Expert's answer
2022-03-15T16:45:59-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS