Assembly Program to Input (Accept) a Multiple Digit Number


The program accepts a number having multiple digits. The basic idea in the program is that the program stores every new digit in the variable value and adds it with total but after multiplying the total with 10 and the result of the sum is stored again in total.

Algorithm:

TOTAL = 0
READ AN ASCII DIGIT
REPEAT
            CONVERT CHARACTER TO BINARY VALUE
            TOTAL = 10 X TOTAL + VALUE
            READ A CHARACTER
UNTIL CHARACTER IS CARRIAGE RETURN


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
.MODEL SMALL
.STACK 100H
.DATA
MSG DB "ENTER A NUMBER: $"
TOTAL DB 0
VALUE DB 0
.CODE
MAIN PROC
    
    MOV AX, @DATA
    MOV DS, AX
    
    MOV AH, 9
    LEA DX, MSG
    INT 21H
    
    READ:
    MOV AH, 1
    INT 21H
    
    CMP AL, 13
    JE ENDOFNUMBER
    
    MOV VALUE, AL
    SUB VALUE, 48
    
    MOV AL, TOTAL
    MOV BL, 10
    MUL BL
    
    ADD AL, VALUE
    
    MOV TOTAL, AL
    
    JMP READ

    ENDOFNUMBER:   

MAIN ENDP

Output:


No comments