Assembly Program to check whether a number is Positive or Negative


The program prompts the user to input a number and tells whether the input number is Positive or Negative. The program can take a multidigit number as input.

The basic logic in the program is that after taking the number from the user, the program compare the number with zero if it's greater then jump to label POSITIVE otherwise prints its a negative number.

 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
.MODEL SMALL
.STACK 100H
.DATA
MSG DB "ENTER A NUMBER: $"
NEGATIVEMSG DB 0DH, 0AH, "NUMBER IS NEGATIVE $" 
POSITIVEMSG DB 0DH, 0AH, "NUMBER IS POSITIVE $"
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:
    
    MOV AL, TOTAL
    CMP AL, 0
    JGE POSITIVE
    
    MOV AH, 9
    LEA DX, NEGATIVEMSG
    INT 21H
    
    JMP EXIT
    
    POSITIVE:
    
    MOV AH, 9
    LEA DX, POSITIVEMSG
    INT 21H
    
    EXIT:   

MAIN ENDP

Output:

No comments